PushNotificationIOS.requestPermissions promise never resolves
See original GitHub issueI’m confused as to how this is supposed to be used. The RN PushNotificationIOS docs say:
This method returns a promise that will resolve when the user accepts, rejects, or if the permissions were previously rejected. The promise resolves to the current state of the permission.
But when I use the following, console.log()
is never hit.
PushNotificationIOS.requestPermissions().then((permissions) => console.log(permissions));
What am I missing?
Issue Analytics
- State:
- Created 7 years ago
- Reactions:9
- Comments:23 (10 by maintainers)
Top Results From Across the Web
react native - PushNotificationIOS.requestPermissions() callback
I'm trying to use it like so: PushNotificationIOS.requestPermissions().then((permissions) => console.log(permissions)); but that doesn't ever ...
Read more >PushNotificationIOS - React Native
This method returns a promise. If the app was launched by a push notification, this promise resolves to an object of type PushNotificationIOS...
Read more >PushNotificationIOS.requestPermissions never resolves in RN 0.56.0
PushNotificationIOS.requestPermissions never resolves in RN 0.56.0 ... This issue was originally created by @jongirard as facebook/react-native#20821. <!-- ...
Read more >react-native-community/push-notification-ios - npm.io
Check @react-native-community/push-notification-ios 1.10.1 package - Last ... If the app was launched by a push notification, this promise resolves to an ...
Read more >Notification.requestPermission() - Web APIs | MDN
The requestPermission() method of the Notification interface ... A Promise that resolves to a string with the permission picked by the user.
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Figured out something very strange…
In order for
PushNotificationIOS.requestPermissions()
to resolve thePromise
, you need to add an event listener, like this:What’s even more interesting is that it doesn’t even have to be the
'register'
event, it could be'notification'
or'localNotification'
and it will still cause the promise to resolve.So this is what I ended up using anywhere I use
requestPermissions()
and needed to handle the promise:Can at least a couple of you test this and confirm the behaviour. Once it’s reproducible on more than just my machine, I’ll see what’s the cause and issue a PR to fix it.
Thanks.
@joshuapinter ah, gotcha. I was able to repro; denying perms and running app again never resolves promise. As a stopgap the fix also works on my end, e.g.