@@ -28,6 +28,7 @@ @implementation RNVoipPushNotificationManager
2828
2929RCT_EXPORT_MODULE ();
3030
31+ static bool _isVoipRegistered = NO ;
3132static NSMutableDictionary <NSString *, RNVoipPushNotificationCompletion> *completionHandlers = nil ;
3233
3334
@@ -118,22 +119,29 @@ - (void)sendEventWithNameWrapper:(NSString *)name body:(id)body {
118119 }
119120}
120121
121- // --- register voip token
122- - (void )voipRegistration
122+ // --- register delegate for PushKit to delivery credential and remote voip push to your delegate
123+ // --- this usually register once and ASAP after your app launch
124+ + (void )voipRegistration
123125{
126+ if (_isVoipRegistered) {
124127#ifdef DEBUG
125- RCTLog (@" [RNVoipPushNotificationManager] voipRegistration" );
128+ RCTLog (@" [RNVoipPushNotificationManager] voipRegistration is already registered " );
126129#endif
127-
128- dispatch_queue_t mainQueue = dispatch_get_main_queue ();
129- dispatch_async (mainQueue, ^{
130- // --- Create a push registry object
131- PKPushRegistry * voipRegistry = [[PKPushRegistry alloc ] initWithQueue: mainQueue];
132- // --- Set the registry's delegate to AppDelegate
133- voipRegistry.delegate = (RNVoipPushNotificationManager *)RCTSharedApplication ().delegate ;
134- // --- Set the push type to VoIP
135- voipRegistry.desiredPushTypes = [NSSet setWithObject: PKPushTypeVoIP];
136- });
130+ } else {
131+ _isVoipRegistered = YES ;
132+ #ifdef DEBUG
133+ RCTLog (@" [RNVoipPushNotificationManager] voipRegistration enter" );
134+ #endif
135+ dispatch_queue_t mainQueue = dispatch_get_main_queue ();
136+ dispatch_async (mainQueue, ^{
137+ // --- Create a push registry object
138+ PKPushRegistry * voipRegistry = [[PKPushRegistry alloc ] initWithQueue: mainQueue];
139+ // --- Set the registry's delegate to AppDelegate
140+ voipRegistry.delegate = (RNVoipPushNotificationManager *)RCTSharedApplication ().delegate ;
141+ // --- Set the push type to VoIP
142+ voipRegistry.desiredPushTypes = [NSSet setWithObject: PKPushTypeVoIP];
143+ });
144+ }
137145}
138146
139147// --- should be called from `AppDelegate.didUpdatePushCredentials`
@@ -200,7 +208,7 @@ + (void)removeCompletionHandler:(NSString *)uuid
200208 return ;
201209 }
202210 dispatch_async (dispatch_get_main_queue (), ^{
203- [self voipRegistration ];
211+ [RNVoipPushNotificationManager voipRegistration ];
204212 });
205213}
206214
0 commit comments