-
Notifications
You must be signed in to change notification settings - Fork 24.5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
PushNotificationIOS.requestPermissions won't resolve if no event listeners are attached #13263
PushNotificationIOS.requestPermissions won't resolve if no event listeners are attached #13263
Conversation
dbb3cca
to
dff2a98
Compare
cc @frantic, does this fix make sense? |
dff2a98
to
b2398f8
Compare
@@ -249,6 +269,7 @@ - (void)handleRemoteNotificationReceived:(NSNotification *)notification | |||
- (void)handleRemoteNotificationsRegistered:(NSNotification *)notification | |||
{ | |||
[self sendEventWithName:@"remoteNotificationsRegistered" body:notification.userInfo]; | |||
[self stopObservingRegisteredNotifications]; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why do you need to stopObservingRegisteredNotifications
? IIRC when registering for push (not local) notifications, RCTRegisterUserNotificationSettings
is called first, followed by RCTRemoteNotificationsRegistered
if we got push token.
I don't see a reason to stop observing because it adds complexity without much gain.
It's clean and awesome, thanks @peterp! My only suggestion is to not manually unsubscribe from notification center, because it might introduce some racing bugs. |
b2398f8
to
07a6afb
Compare
07a6afb
to
9796f57
Compare
9796f57
to
fc2c7eb
Compare
Nice to see this issue get some attention! Cheers gents. |
@facebook-github-bot shipit |
@javache has imported this pull request. If you are a Facebook employee, you can view this diff on Phabricator. |
…eners are attached Summary: Resolves facebook#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 facebook#13263 Differential Revision: D4851767 Pulled By: javache fbshipit-source-id: 2be8621e072ae1086014594bc986ca5590b5eb61
Motivation
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.
Test Plan
When requesting permissions the promise will resolve:
PushNotificationIOS.requestPermissions().then(console.log);
without the need for callingPushNotificationIOS.addEventListener()
first.