Reputation: 79
Using the PushNotificationIOS library, I am able to get the deviceToken on the register event:
const registerPN = PushNotificationIOS.addEventListener('register', deviceToken => {
console.log("Registering Push Notification Token", deviceToken);
store.dispatch(setPushNotificationToken(userPushNotificationToken));
});
However, if the user initially rejects the notification question, we push them to update the settings through:
Alert.alert(
'Action Required',
`To turn notifications on, you'll need to update your settings`,
[
{
text: 'Go to settings',
onPress: () => {
Linking.openURL('app-settings:');
}
},
{
text: 'Cancel',
style: 'cancel'
}
]
)
If the user then goes to the settings panel, and returns, the 'register' event does not seem to be called, so I'm not sure how to get the device token.
How can I add a listener for the 'settings' update so that I can store the token for pushes from the server?
Upvotes: 1
Views: 155
Reputation: 79
Figured it out.
With a PushNotificationIOS.checkPermissions() call, you can check if they have changed. If so, fire off a PushNotificationIOS.requestPermissions() call that will automatically fire the listener with the correct token.
Upvotes: 1