SDK 40.0.1
Android (Pixel 3a)
expo-server-sdk 3.6.0
Hi, I’m having some issues with heads up notifications. I can send notifications with no problem except they won’t show as heads up, they only appear in the notifications tab.
Here’s the code for the client and server side:
export const registerForPushNotificationsAsync = async () => {
if (Constants.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;
}
const token = (await Notifications.getExpoPushTokenAsync()).data;
return token;
} else {
alert('Must use physical device for Push Notifications');
}
if (Platform.OS === 'android') {
Notifications.setNotificationChannelAsync('default', {
name: 'default',
importance: Notifications.AndroidImportance.MAX,
vibrationPattern: [0, 250, 250, 250],
lightColor: '#FF231F7C',
});
}
};
const { Expo } = require('expo-server-sdk');
// Create a new Expo client
const expo = new Expo();
const sendNotifications = async (pushTokens, title, body) => {
try {
// Create the messages that you want to send to clents
let messages = [];
for (let pushToken of pushTokens) {
// Check that all your push tokens appear to be valid Expo push tokens
if (!Expo.isExpoPushToken(pushToken)) {
console.error(`Push token ${pushToken} is not a valid Expo push token`);
continue;
}
// Construct a message
const message = {
to: pushToken,
sound: 'default',
title,
body,
priority: 'high',
};
messages.push(message);
}
// Batching nofications
let chunks = expo.chunkPushNotifications(messages);
let tickets = [];
(async () => {
for (let chunk of chunks) {
try {
let ticketChunk = await expo.sendPushNotificationsAsync(chunk);
console.log(ticketChunk);
tickets.push(...ticketChunk);
} catch (error) {
console.error(error);
}
}
})();
} catch (err) {
console.log(err);
}
};
module.exports = {
sendNotifications,
expo,
};
Any help would be appreciated. Thanks!