Help please!
Problem 1: If I don’t allow notifications on Expo, I never get the Notifications Permissions Prompt.
Problem 2: If I do allow them and use the code in the Expo docs (https://docs.expo.io/versions/latest/guides/push-notifications), then I get a warning that says “Possible Unhandled Promise Rejection”, and the token never loads.
Problem 3: Once I remove the await in the let token = await Notifications.getExpoPushTokenAsync();
I get a Promise that says:
Promise { [16:09:25] "_40": 0, [16:09:25] "_55": null, [16:09:25] "_65": 0, [16:09:25] "_72": null, [16:09:25] }}
This wasn’t what I was expecting for, since I was expecting something like a
ExponentPushToken[xxxxxxxxxxxxxxxxxxxxxx]
Here is my code:
const PUSH_ENDPOINT = 'https://your-server.com/users/push-token';
export async function registerForPushNotificationsAsync() {
const { status: existingStatus } = await Permissions.getAsync(
Permissions.NOTIFICATIONS
);
let finalStatus = existingStatus;
// only ask if permissions have not already been determined, because
// iOS won't necessarily prompt the user a second time.
if (existingStatus !== 'granted') {
// Android remote notification permissions are granted during the app
// install, so this will only ask on iOS
const { status } = await Permissions.askAsync(Permissions.NOTIFICATIONS);
finalStatus = status;
}
// Stop here if the user did not grant permissions
if (finalStatus !== 'granted') {
return;
}
// Get the token that uniquely identifies this device
let token = await Notifications.getExpoPushTokenAsync();
console.log("im the token: ", token);
}