Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
PushNotificationIOS requestPermission promisified
Summary: **Motivation** Today it's hard to build a good flow around requesting permissions if we don't know when the user rejects the push notification permission. With this PR I wrap `PushNotificationIOS#requestPermission` in a promise. The promise will return with the updated permissions when the user accepts, rejects or has previously rejected the permission. An example flow of how an app should handle push notifications with the change proposed: 1) Show user an explanation of push notification permissions with a button to enable, 2) User presses the enable push notifications button, 3) If the user accepts -> take them into the app, 4) if the user rejects -> explain how to enable permission in the settings app. 5) My app will now store some state about how it has asked permissions for push notifications so that the next time the user is taken through this flow they will go straight to step 4. Without this change we could listen to the `register` event that PushNotificationIOS fires on the success sc Closes #7900 Differential Revision: D3387424 Pulled By: nicklockwood fbshipit-source-id: e27df41e83216e4e2a14d1e42c6b26e72236f48c
- Loading branch information
f4dbf37
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.
Not working on RN .31 iOS
f4dbf37
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.
Similar Issue: Using RN 0.31
PushNotificationIOS.requestPermissions().then(permission => { });
working for the first time.
explaining the scenario and issue facing,
PushNotificationIOS.addEventListener('register', (token) => { });
listener gets called and i am able to receive token,
But this time my register event never gets fired , so no token.
incase if the user turns on notification in the settings I would like to receive token again.
for that i tried
PushNotificationIOS.requestPermissions().then(permission => { });
but its never getting called and not able to generate token again.
so finally it seems
PushNotificationIOS.requestPermissions().then(permission => { });
works only for the first time, second time its not opening the request popup.
Thanks in Advance
f4dbf37
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.
Super strange but 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'
as well and they all work.So this is what I ended up using anywhere I needed to get and handle the
requestPermissions()
Promise resolve: