mirror of
https://github.com/status-im/react-native.git
synced 2025-02-04 21:53:30 +00:00
PushNotificationIOS.requestPermissions won't resolve if no event listeners are attached
Summary: Resolves #13012 RCTPushNotificationManager uses startObserving to register for RCTRegisterUserNotificationSettings. According to the docs, the startObserving method won't be called until somebody subscribes to NotificationManagerIOS. This means there is a scenario when the developer can call requestPermissions without subscribing to notifications first, but since RCTPushNotificationManager relies on NSNotificationCenter subscribtion, the result will never be returned. When requesting permissions the promise will resolve: `PushNotificationIOS.requestPermissions().then(console.log);` without the need for calling `PushNotificationIOS.addEventListener()` first. Closes https://github.com/facebook/react-native/pull/13263 Differential Revision: D4851767 Pulled By: javache fbshipit-source-id: 2be8621e072ae1086014594bc986ca5590b5eb61
This commit is contained in:
parent
5767b98f4d
commit
d03f9b7442
@ -142,6 +142,15 @@ RCT_EXPORT_MODULE()
|
||||
selector:@selector(handleRemoteNotificationReceived:)
|
||||
name:RCTRemoteNotificationReceived
|
||||
object:nil];
|
||||
[self startObservingRegistrationNotifications];
|
||||
}
|
||||
|
||||
- (void)startObservingRegistrationNotifications
|
||||
{
|
||||
[[NSNotificationCenter defaultCenter] addObserver:self
|
||||
selector:@selector(handleRegisterUserNotificationSettings:)
|
||||
name:RCTRegisterUserNotificationSettings
|
||||
object:nil];
|
||||
[[NSNotificationCenter defaultCenter] addObserver:self
|
||||
selector:@selector(handleRemoteNotificationsRegistered:)
|
||||
name:RCTRemoteNotificationsRegistered
|
||||
@ -150,10 +159,6 @@ RCT_EXPORT_MODULE()
|
||||
selector:@selector(handleRemoteNotificationRegistrationError:)
|
||||
name:RCTErrorRemoteNotificationRegistrationFailed
|
||||
object:nil];
|
||||
[[NSNotificationCenter defaultCenter] addObserver:self
|
||||
selector:@selector(handleRegisterUserNotificationSettings:)
|
||||
name:RCTRegisterUserNotificationSettings
|
||||
object:nil];
|
||||
}
|
||||
|
||||
- (void)stopObserving
|
||||
@ -319,6 +324,7 @@ RCT_EXPORT_METHOD(requestPermissions:(NSDictionary *)permissions
|
||||
return;
|
||||
}
|
||||
|
||||
[self startObservingRegistrationNotifications];
|
||||
_requestPermissionsResolveBlock = resolve;
|
||||
|
||||
UIUserNotificationType types = UIUserNotificationTypeNone;
|
||||
|
Loading…
x
Reference in New Issue
Block a user