Skip to content

Commit

Permalink
support voipRegistration in AppDelegate.m
Browse files Browse the repository at this point in the history
  • Loading branch information
zxcpoiu committed Nov 18, 2020
1 parent c803762 commit b242ffb
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 14 deletions.
1 change: 1 addition & 0 deletions ios/RNVoipPushNotification/RNVoipPushNotificationManager.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ typedef void (^RNVoipPushNotificationCompletion)(void);

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

+ (void)voipRegistration;
+ (void)didUpdatePushCredentials:(PKPushCredentials *)credentials forType:(NSString *)type;
+ (void)didReceiveIncomingPushWithPayload:(PKPushPayload *)payload forType:(NSString *)type;
+ (void)addCompletionHandler:(NSString *)uuid completionHandler:(RNVoipPushNotificationCompletion)completionHandler;
Expand Down
36 changes: 22 additions & 14 deletions ios/RNVoipPushNotification/RNVoipPushNotificationManager.m
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ @implementation RNVoipPushNotificationManager

RCT_EXPORT_MODULE();

static bool _isVoipRegistered = NO;
static NSMutableDictionary<NSString *, RNVoipPushNotificationCompletion> *completionHandlers = nil;


Expand Down Expand Up @@ -118,22 +119,29 @@ - (void)sendEventWithNameWrapper:(NSString *)name body:(id)body {
}
}

// --- register voip token
- (void)voipRegistration
// --- register delegate for PushKit to delivery credential and remote voip push to your delegate
// --- this usually register once and ASAP after your app launch
+ (void)voipRegistration
{
if (_isVoipRegistered) {
#ifdef DEBUG
RCTLog(@"[RNVoipPushNotificationManager] voipRegistration");
RCTLog(@"[RNVoipPushNotificationManager] voipRegistration is already registered");
#endif

dispatch_queue_t mainQueue = dispatch_get_main_queue();
dispatch_async(mainQueue, ^{
// --- Create a push registry object
PKPushRegistry * voipRegistry = [[PKPushRegistry alloc] initWithQueue: mainQueue];
// --- Set the registry's delegate to AppDelegate
voipRegistry.delegate = (RNVoipPushNotificationManager *)RCTSharedApplication().delegate;
// --- Set the push type to VoIP
voipRegistry.desiredPushTypes = [NSSet setWithObject:PKPushTypeVoIP];
});
} else {
_isVoipRegistered = YES;
#ifdef DEBUG
RCTLog(@"[RNVoipPushNotificationManager] voipRegistration enter");
#endif
dispatch_queue_t mainQueue = dispatch_get_main_queue();
dispatch_async(mainQueue, ^{
// --- Create a push registry object
PKPushRegistry * voipRegistry = [[PKPushRegistry alloc] initWithQueue: mainQueue];
// --- Set the registry's delegate to AppDelegate
voipRegistry.delegate = (RNVoipPushNotificationManager *)RCTSharedApplication().delegate;
// --- Set the push type to VoIP
voipRegistry.desiredPushTypes = [NSSet setWithObject:PKPushTypeVoIP];
});
}
}

// --- should be called from `AppDelegate.didUpdatePushCredentials`
Expand Down Expand Up @@ -200,7 +208,7 @@ + (void)removeCompletionHandler:(NSString *)uuid
return;
}
dispatch_async(dispatch_get_main_queue(), ^{
[self voipRegistration];
[RNVoipPushNotificationManager voipRegistration];
});
}

Expand Down

0 comments on commit b242ffb

Please sign in to comment.