I'm working on a push notifications system with Expo. I tried to get token and save it to mobile storage:
/**
* Demande d'autorisation pour accéder au token du GSM et l'envoyer vers l'api
*/
registerForPush = async () => {
if (Constants.isDevice) {
const { status: existingStatus } = await Permissions.getAsync(
Permissions.NOTIFICATIONS,
);
let finalStatus = existingStatus;
if (existingStatus !== 'granted') {
const { status } = await Permissions.askAsync(
Permissions.NOTIFICATIONS,
);
finalStatus = status;
}
if (finalStatus !== 'granted') {
alert('Failed to get push token for push notification!');
return;
}
const gsm = await Notifications.getExpoPushTokenAsync();
this._storeData('TOKEN_GSM', gsm);
} else {
alert('Must use physical device for Push Notifications');
}
};
Component Did Mount :
async componentDidMount() {
console.log("########## COMPONENT DID MOUNT ############");
this.registerForPush();
I got the token in android mobile but in IOS i got null value.