Unable to get user expo push token, allow notifications gets insta denied on standalone app (apk) but expo go works fine

Hello everyone, i have a simple function that i got from expo docs to get the user expo push token, but everytime it runs gets insta denied, even when it prompts and i allow notifications im unable to get the user token because on the app its still denied and “canAskAgain” is always false. I have a button that calls the following code:

async function registerForPushNotificationsAsync() {
let token;

if (Platform.OS === ‘android’) {
await Notifications.setNotificationChannelAsync(‘default’, {
name: ‘default’,
importance: Notifications.AndroidImportance.MAX,
vibrationPattern: [0, 250, 250, 250],
lightColor: ‘#FF231F7C’,
});
}

if (Device.isDevice) {
const { status: existingStatus } = await Notifications.getPermissionsAsync();
let finalStatus = existingStatus;
if (existingStatus !== ‘granted’) {
const { status } = await Notifications.requestPermissionsAsync();
finalStatus = status;
}
if (finalStatus !== ‘granted’) {
alert(‘Failed to get push token for push notification!’);
setPermissions(finalStatus)
}
token = (await Notifications.getExpoPushTokenAsync({ projectId: “MyProjectId” })).data;
console.log(token);
} else {
alert(‘Must use physical device for Push Notifications’);
}

setPushToken(token)
}

Any help is really appreciated

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.