I have already specified the notification channel in my backend code, but somehow the client doesn’t receive the notification in the specified channel. I also set the notification channel for the client. I already followed the doc, but the notifications are received as Miscellaneous
, as mentioned in the documentation on handling-notification-channels.
This the snippet of my code:
Backend
for (let pushToken of savedPushTokens) {
if (!Expo.isExpoPushToken(pushToken)) {
console.error(`Push token ${pushToken} is not a valid Expo push token`);
continue;
}
notifications.push({
to: pushToken,
sound: "default",
title: title,
body: body,
data: data,
sound: "default",
priority: "high",
channelId: "test",
});
}
Client/mobile
async function registerForPushNotificationsAsync() {
let token;
if (Platform.OS === "android") {
await Notifications.setNotificationChannelAsync("test", {
name: "Test",
importance: Notifications.AndroidImportance.MAX,
sound: true,
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!");
return;
}
// Learn more about projectId:
// https://docs.expo.dev/push-notifications/push-notifications-setup/#configure-projectid
token = (
await Notifications.getExpoPushTokenAsync({
projectId: Constants.expoConfig.extra.eas.projectId,
})
).data;
} else {
alert("Must use physical device for Push Notifications");
}
return token;
}
What did I miss here?