I made the setup for push notifications using the expo push system and it works fine when using the app through ExpoGo. But in the installed app from the play store, it doesnt work. Debugging the app I found out that the
token = (await Notifications.getExpoPushTokenAsync()).data;
is returning nothing because the alert after it never runs.
async function registerForPushNotificationsAsync() {
let token;
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;
}
alert('1')
token = (await Notifications.getExpoPushTokenAsync()).data;
alert('2')
if (Platform.OS === 'android') {
Notifications.setNotificationChannelAsync('default', {
name: 'default',
importance: Notifications.AndroidImportance.MAX,
vibrationPattern: [0, 250, 250, 250],
lightColor: '#FF231F7C',
});
}
//sending the token to my api
api.put('xxx', {
notification_token: token,
});
}
What should I do? Is anything I am missing? I just used the codes given in the docs https://docs.expo.io/push-notifications/overview/