I'm trying to receive a push notification token from my app, but I never get a token. I tried debugging using a few alerts, and I can see that I get "granted" returned when accepting notifications. I have only tested for iOS.
i'm running
"expo": "^32.0.0",
"react-native": "https://github.com/expo/react-native/archive/sdk-32.0.0.tar.gz",
I tried using the guide from https://docs.expo.io/versions/latest/guides/push-notifications/
Since it didn't work i tried the snack they provided from the API reference: https://docs.expo.io/versions/v32.0.0/sdk/notifications/
snack: https://snack.expo.io/@documentation/pushnotifications
This is my current code:
static registerForPushNotificationsAsync = async kid => {
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;
}
let token = await Notifications.getExpoPushTokenAsync();
alert("finalstatus " + finalStatus);
alert("existing status " + existingStatus);
alert(token);
// POST the token to your backend server from where you can retrieve it to send push notifications.
return await fetch(`${Api.APIEndpoint}/app/notification`, {
method: "POST",
headers: {
Accept: "application/json",
"Content-Type": "application/json"
},
body: JSON.stringify({
token: token,
kid: kid
})
});
} else {
alert("Must use physical device for Push Notifications");
}
};
the first two alerts triggers as expected (and returns "granted" when I accept), but alert(token) seems to be empty.
I also noticed that I get asked for two permissions. First it asks for permission to use notifications and then it asks for access to photos. I don't need permissison to photos and I am curious why it asks for that.
As far as I have understood reading the documentation, FCM is required only for android devices? I will need it to work on android as well, but I figured making it work for one platform first and then move on.
I installed the app on my iPhones using Testflight. Does the token only "appear" once the app is approved for the app store?
Maybe there's something else i missed in the documentation.
Any help or point in the right direction will be much appreciated.