mirror of
https://github.com/zhigang1992/react-native-firebase.git
synced 2026-04-23 12:06:47 +08:00
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:
@@ -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;
|
||||
|
||||
@@ -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];
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user