react-native-push-notification
react-native-push-notification copied to clipboard
GetToken Method
Feature Request
A method to get the token.
Why it is needed
It would be easier to use the package. Currently you have to save the token from the configure method.
Code sample
PushNotification.getToken(function (token) {
console.log(token);
});
Is there any decisions/progress on this one?
Because we hit a problem with iOS real devices, where we ask for the system permissions later in the app (when we present a custom dialog), however it seems that the token at that point of time is not generated and stays empty. We use the following code:
Notifications.configure({ onRegister: async ({ token }) => { await AsyncStorage.setItem("token", token); }, onNotification: (notification: PushNotification) => { notification.finish(PushNotificationIOS.FetchResult.NoData); }, onRegistrationError: (err) => { // log exception }, permissions: { alert: true, badge: true, sound: true }, popInitialNotification: true, requestPermissions: false });
Could please someone advise what we should do/change to avoid this issues?
+1
AsyncStorage
This is how I did mine and seems to work, the only thing I wish could get done is re-creating token on account login or such but I have no idea how to.
onRegister: async token => { if (token) { await AsyncStorage.setItem(
@${COMPANY_TREE}/notificationToken, JSON.stringify(token), err => { if (err) { console.log('PushNotification onRegister error:', err); } else { console.log('PushNotification onRegister saved!', token); } }, ).catch(err => { console.log('error is: ' + err); console.log('PushNotification onRegister error:', err); }); } },
+1