Reputation: 47
let expo = new Expo({ accessToken: process.env.EXPO_ACCESS_TOKEN,useFcmV1: true});
con.query(
`SELECT expo_push_token,online_status FROM user WHERE id="${id}"`,
function (err, result_status, fields) {
if (err) {
res.send("Fail");
throw err;
}
let messages=[]
messages.push({
to:result_status[0].expo_push_token,
sound: 'default',
title:"TestNotification",
body: `${user_name} has sent a message`,
data: { withSome: 'data' },
})
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);
}
}
})();
}
)
The above push notification setup for backend (NodeJS) works with Expo GO but when built with eas in development fails to fetch or send notifications. I am getting the tokens right and testing the notification using expo browser push notification tool,works. Is anyone else facing the same issue and if so how did you solve it. In my understanding backend code has got nothing to do with me building with eas or just using expo GO, so don't understand why its not pushing the notifications when the tokens are being correctly retrieved.
Upvotes: 0
Views: 198
Reputation: 53
When you are force pushing V1, you need to add it at the end of the query like so:
send?useFcmV1=true
const response = await fetch('https://exp.host/--/api/v2/push/send?useFcmV1=true', {
method: 'POST',
headers: {
Accept: 'application/json',
'Accept-encoding': 'gzip, deflate',
'Content-Type': 'application/json',
},
body: JSON.stringify(message),
});
Upvotes: 0