I try to catch a fcm token from my app react native . No problem for android but for ios i have an error saying
code: ‘messaging/invalid-argument’,
message: ‘The registration token is not a valid FCM registration token’
i follow the doc , i do this in front end
export const getFcmToken = async () => {
const projectId =
Constants?.expoConfig?.extra?.eas?.projectId ??
Constants?.easConfig?.projectId;
console.log("constatrn", Constants.expoConfig);
try {
const { status: existingStatus } =
await Notifications.getPermissionsAsync();
let finalStatus = existingStatus;
if (existingStatus !== "granted") {
const { status } = await Notifications.requestPermissionsAsync();
finalStatus = status;
}
if (finalStatus !== "granted") {
alert("Échec de l'obtention du jeton pour les notifications push!");
return;
}
const token = (await Notifications.getDevicePushTokenAsync()).data;
console.log("Jeton Expo Push:", token);
return token;
} catch (error) {
console.error("Erreur lors de l'obtention du jeton Expo push:", error);
}
};
Then i call it with firebase Admin in my back this way
const sendNotification = async (
userID: string,
title: string,
body: string
) => {
try {
let tokenArray: string[] = [];
const getTok = await getToken(userID);
getTok?.map((item: any) => {
tokenArray.push(item.token);
});
console.log("tokenArray", tokenArray);
// Envoyez la notification
await firebaseAdmin
.messaging()
.sendEachForMulticast({
tokens: tokenArray, // ['token_1', 'token_2', ...]
data: {
owner: "test",
user: "test",
picture: "",
},
apns: {
payload: {
aps: {
// Required for background/quit data-only messages on iOS
// Note: iOS frequently will receive the message but decline to deliver it to your app.
// This is an Apple design choice to favor user battery life over data-only delivery
// reliability. It is not under app control, though you may see the behavior in device logs.
"content-available": true,
// Required for background/quit data-only messages on Android
priority: "high",
},
},
},
})
.then((response: any) => {
console.log("Response sent message:", response.responses[0].error);
})
.catch((error) => {
console.log("Error sending message:", error);
});
} catch (error) {
console.error("Erreur lors de l'envoi de la notification:", error);
}
};
Do i forget something in the front end to catch the good token ?
I tried to use expo notification to catch the fcm token but it looks like i catch the apns token