Please provide the following:
- SDK Version: 4.12.1
- Platforms(Android/iOS/web/all): iOS
- Add the appropriate “Tag” based on what Expo library you have a question on.
I am using AWS Amplify on a React-Native app and have followed this tutorial which uses expo-server-sdk
to send push notifications. I am getting this error in my Lambda function:
{
status: 'error',
message: '"{type=expo, data=ExponentPushToken[nAvY4DCkl2lINEdIpdzLCV]}" is
not a registered push notification recipient',
details: { error: 'DeviceNotRegistered' }
}
Not sure what is going on here, first time using Expo push notifications.
My lambda code is as follows:
/* Amplify Params - DO NOT EDIT
You can access the following resource attributes as environment variables from your Lambda function
var environment = process.env.ENV
var region = process.env.REGION
var apiPushAPIGraphQLAPIIdOutput = process.env.API_PUSHAPI_GRAPHQLAPIIDOUTPUT
var apiPushAPIGraphQLAPIEndpointOutput = process.env.API_PUSHAPI_GRAPHQLAPIENDPOINTOUTPUT
Amplify Params - DO NOT EDIT */
const { Expo } = require("expo-server-sdk");
// Create a new Expo SDK client
let expo = new Expo();
exports.handler = function(event, context, callback) {
try {
let messages = [];
// prettier-ignore
for (var key in event.Endpoints) {
if (event.Endpoints.hasOwnProperty(key)) {
var endpoint = event.Endpoints[key];
messages.push({
to: String(endpoint.User.UserAttributes.expoToken),
sound: "default",
body: event.Message.apnsmessage.body,
data: { "status": "ok" }
});
}
}
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);
}
}
})();
let receiptIds = [];
for (let ticket of tickets) {
if (ticket.id) {
receiptIds.push(ticket.id);
}
}
let receiptIdChunks = expo.chunkPushNotificationReceiptIds(receiptIds);
async () => {
for (let chunk of receiptIdChunks) {
try {
let receipts = await expo.getPushNotificationReceiptsAsync(chunk);
console.log(receipts);
for (let receipt of receipts) {
if (receipt.status === "ok") {
continue;
} else if (receipt.status === "error") {
console.error(
`There was an error sending a notification: ${receipt.message}`
);
if (receipt.details && receipt.details.error) {
console.error(`The error code is ${receipt.details.error}`);
}
}
}
} catch (error) {
console.error(error);
}
}
};
callback(null, event.Endpoints);
} catch (error) {
callback(error);
}
};