Description
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.
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
PushNotificationIOS.requestPermissions().then(console.log);
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):
PushNotificationIOS.addEventListener('localNotification', () => {});
PushNotificationIOS.requestPermissions().then(console.log);
Now "Allow" button will work as expected, the promise will be resolved and you'll see log entry.
Additional Information
- React Native version: 0.42.0
- Platform: iOS
- Operating System: macOS
Description
RCTPushNotificationManagerusesstartObservingto register forRCTRegisterUserNotificationSettings. According to the docs, thestartObservingmethod won't be called until somebody subscribes toNotificationManagerIOS.This means there is a scenario when the developer can call
requestPermissionswithout subscribing to notifications first, but sinceRCTPushNotificationManagerrelies onNSNotificationCentersubscribtion, 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