fix(messaging): fix remote notification tokens

* Don't abort registerForRemoteNotifications

The native call to `registerForRemoteNotifications` shouldn't be aborted even if `isRegisteredForRemoteNotifications` returns `true`. This is because after successful registration on the first boot, on successive boots the app `isRegisteredForRemoteNotifications` will return true, and then `registerForRemoteNotifications` won't be called again and therefore the APNSToken will never be set (because it is only set on the `didRegisterForRemoteNotificationsWithDeviceToken` swizzled by the `FIRMessagingRemoteNotificationsProxy`)

* Set APNSToken on didRegisterForRemoteNotificationsWithDevicetoken

This is what `FIRMessagingRemoteNotificationsProxy` does, and doing it here seems to avoid the race condition caused by `didRegisterForRemoteNotificationsWithDeviceToken` here being executed first and resolving the promise before the token is set (at least on iOS 12). It doesn't do any damage anyway to do it here first anyway.

Co-authored-by: Russell Wheatley <russellwheatley85@gmail.com>
This commit is contained in:
Ely Alvarado
2020-03-12 09:27:19 -05:00
committed by GitHub
parent d67c099fc9
commit bd4dc06a05
2 changed files with 1 additions and 4 deletions

View File

@@ -44,6 +44,7 @@
// called when `registerForRemoteNotifications` completes successfully
- (void)application:(UIApplication *)application didRegisterForRemoteNotificationsWithDeviceToken:(NSData *)deviceToken {
[FIRMessaging messaging].APNSToken = deviceToken;
if (_registerPromiseResolver != nil) {
_registerPromiseResolver(@([RCTConvert BOOL:@([UIApplication sharedApplication].isRegisteredForRemoteNotifications)]));
_registerPromiseResolver = nil;

View File

@@ -181,10 +181,6 @@ RCT_EXPORT_METHOD(registerForRemoteNotifications:
(RCTPromiseResolveBlock) resolve
: (RCTPromiseRejectBlock) reject
) {
if ([UIApplication sharedApplication].isRegisteredForRemoteNotifications == YES) {
return resolve(@([RCTConvert BOOL:@(YES)]));
}
[[RNFBMessagingAppDelegateInterceptor sharedInstance] setPromiseResolve:resolve andPromiseReject:reject];
[[UIApplication sharedApplication] registerForRemoteNotifications];
}