question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

PushNotificationIOS.requestPermissions promise never resolves

See original GitHub issue

I’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:closed
  • Created 7 years ago
  • Reactions:9
  • Comments:23 (10 by maintainers)

github_iconTop GitHub Comments

15reactions
joshuapintercommented, Sep 11, 2016

Figured out something very strange…

In order for PushNotificationIOS.requestPermissions() to resolve the Promise, you need to add an event listener, like this:

PushNotificationIOS.addEventListener('register', (token) => {});

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:

componentWillMount() {
  // NOTE: You absolutely need this for requestPermissions() promise to resolve.   
  PushNotificationIOS.addEventListener('register', (token) => {});
}

componentWillUnmount() {
  PushNotificationIOS.removeEventListener('register', (token) => {});
}

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.

3reactions
onpawscommented, Sep 15, 2016

@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.

PushNotificationIOS.addEventListener('register', (token) => {});
PushNotificationIOS.requestPermissions().then((perms) => console.log(perms));
Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found