@@ -60,10 +60,30 @@ @implementation RNVoipPushNotificationManager
60
60
RCT_EXPORT_MODULE ();
61
61
62
62
@synthesize bridge = _bridge;
63
+ static NSMutableDictionary <NSString *, RNVoipPushNotificationCompletion> *completionHandlers = nil ;
64
+
65
+ + (NSMutableDictionary *)completionHandlers {
66
+ if (completionHandlers == nil ) {
67
+ completionHandlers = [NSMutableDictionary new ];
68
+ }
69
+ return completionHandlers;
70
+ }
63
71
64
72
- (void )dealloc
65
73
{
66
74
[[NSNotificationCenter defaultCenter ] removeObserver: self ];
75
+
76
+ // --- invoke complete() and remove for all completionHanders
77
+ for (NSString *uuid in [RNVoipPushNotificationManager completionHandlers ]) {
78
+ RNVoipPushNotificationCompletion completion = [[RNVoipPushNotificationManager completionHandlers ] objectForKey: uuid];
79
+ if (completion) {
80
+ dispatch_async (dispatch_get_main_queue (), ^{
81
+ completion ();
82
+ });
83
+ }
84
+ }
85
+
86
+ [[RNVoipPushNotificationManager completionHandlers ] removeAllObjects ];
67
87
}
68
88
69
89
- (void )setBridge : (RCTBridge *)bridge
@@ -190,6 +210,31 @@ - (void)handleRemoteNotificationReceived:(NSNotification *)notification
190
210
body: notification.userInfo];
191
211
}
192
212
213
+ + (void )addCompletionHandler : (NSString *)uuid completionHandler : (RNVoipPushNotificationCompletion)completionHandler
214
+ {
215
+ self.completionHandlers [uuid] = completionHandler;
216
+ }
217
+
218
+ + (void )removeCompletionHandler : (NSString *)uuid
219
+ {
220
+ self.completionHandlers [uuid] = nil ;
221
+ [self .completionHandlers removeObjectForKey: uuid];
222
+ }
223
+
224
+ RCT_EXPORT_METHOD (onVoipNotificationCompleted:(NSString *)uuid)
225
+ {
226
+ RNVoipPushNotificationCompletion completion = [[RNVoipPushNotificationManager completionHandlers ] objectForKey: uuid];
227
+ if (completion) {
228
+ [RNVoipPushNotificationManager removeCompletionHandler: uuid];
229
+ dispatch_async (dispatch_get_main_queue (), ^{
230
+ NSLog (@" [RNVoipPushNotificationManager] onVoipNotificationCompleted() complete(). uuid = %@ " , uuid);
231
+ completion ();
232
+ });
233
+ } else {
234
+ NSLog (@" [RNVoipPushNotificationManager] onVoipNotificationCompleted() not found. uuid = %@ " , uuid);
235
+ }
236
+ }
237
+
193
238
RCT_EXPORT_METHOD (requestPermissions:(NSDictionary *)permissions)
194
239
{
195
240
if (RCTRunningInAppExtension ()) {
0 commit comments