Skip to content

Commit

Permalink
cache lastVoipToken and return it when subsequently call to registerV…
Browse files Browse the repository at this point in the history
…oipToken
  • Loading branch information
zxcpoiu committed Jan 15, 2021
1 parent ab54fd9 commit 3d1b675
Showing 1 changed file with 7 additions and 2 deletions.
9 changes: 7 additions & 2 deletions ios/RNVoipPushNotification/RNVoipPushNotificationManager.m
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ @implementation RNVoipPushNotificationManager
RCT_EXPORT_MODULE();

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


Expand Down Expand Up @@ -125,8 +126,10 @@ + (void)voipRegistration
{
if (_isVoipRegistered) {
#ifdef DEBUG
RCTLog(@"[RNVoipPushNotificationManager] voipRegistration is already registered");
RCTLog(@"[RNVoipPushNotificationManager] voipRegistration is already registered. return _lastVoipToken = %@", _lastVoipToken);
#endif
RNVoipPushNotificationManager *voipPushManager = [RNVoipPushNotificationManager allocWithZone: nil];
[voipPushManager sendEventWithNameWrapper:RNVoipPushRemoteNotificationsRegisteredEvent body:_lastVoipToken];
} else {
_isVoipRegistered = YES;
#ifdef DEBUG
Expand Down Expand Up @@ -161,8 +164,10 @@ + (void)didUpdatePushCredentials:(PKPushCredentials *)credentials forType:(NSStr
[hexString appendFormat:@"%02x", bytes[i]];
}

_lastVoipToken = [hexString copy];

RNVoipPushNotificationManager *voipPushManager = [RNVoipPushNotificationManager allocWithZone: nil];
[voipPushManager sendEventWithNameWrapper:RNVoipPushRemoteNotificationsRegisteredEvent body:[hexString copy]];
[voipPushManager sendEventWithNameWrapper:RNVoipPushRemoteNotificationsRegisteredEvent body:_lastVoipToken];
}

// --- should be called from `AppDelegate.didReceiveIncomingPushWithPayload`
Expand Down

0 comments on commit 3d1b675

Please sign in to comment.