-
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 #13012

Comments

@frantic If you are okay with it. I would like to take a stab at this. |
@binoy14 sure! |
@frantic Can you point me in the right direction? I am not sure which file to edit and what exactly to do. |
@binoy14 how familiar are you with React Native? I'd recommend starting with building a simple app that uses local notifications. Then you can try reproduce this bug locally on your computer. Once you have the repro case, check out PushNotificationsIOS native module (Objective-C) and see if you can move some event subscriptions out of |
…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
This issue has been moved to react-native-push-notification/ios#3. |

Description
RCTPushNotificationManager
usesstartObserving
to register forRCTRegisterUserNotificationSettings
. According to the docs, thestartObserving
method won't be called until somebody subscribes toNotificationManagerIOS
.This means there is a scenario when the developer can call
requestPermissions
without subscribing to notifications first, but sinceRCTPushNotificationManager
relies onNSNotificationCenter
subscribtion, the result will never be returned.This should be fairly straightforward to solve for somebody new to React Native. Feel free to send a PR!
Reproduction
Have this in your JS file
You'll see iOS permissions dialog, however pressing "Allow" won't resolve the promise and nothing will be printed to the console.
Solution
Change the code to this, then uninstall and run the app again (needed to reset iOS permissions cache):
Now "Allow" button will work as expected, the promise will be resolved and you'll see log entry.
Additional Information
The text was updated successfully, but these errors were encountered: