Skip to content

Commit b242ffb

Browse files
committed
support voipRegistration in AppDelegate.m
1 parent c803762 commit b242ffb

File tree

2 files changed

+23
-14
lines changed

2 files changed

+23
-14
lines changed

ios/RNVoipPushNotification/RNVoipPushNotificationManager.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ typedef void (^RNVoipPushNotificationCompletion)(void);
1717

1818
@property (nonatomic, strong) NSMutableDictionary<NSString *, RNVoipPushNotificationCompletion> *completionHandlers;
1919

20+
+ (void)voipRegistration;
2021
+ (void)didUpdatePushCredentials:(PKPushCredentials *)credentials forType:(NSString *)type;
2122
+ (void)didReceiveIncomingPushWithPayload:(PKPushPayload *)payload forType:(NSString *)type;
2223
+ (void)addCompletionHandler:(NSString *)uuid completionHandler:(RNVoipPushNotificationCompletion)completionHandler;

ios/RNVoipPushNotification/RNVoipPushNotificationManager.m

Lines changed: 22 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ @implementation RNVoipPushNotificationManager
2828

2929
RCT_EXPORT_MODULE();
3030

31+
static bool _isVoipRegistered = NO;
3132
static 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

Comments
 (0)