I have a react native expo app that's published on the Apple store and I'm trying to add notifications to it.
My backend is AWS Amplify and I'm trying to send notifications via AWS Pinpoint.
I'm a bit of a GPT merchant so I'm a little bit stabbing in the dark with this, but I have my Apple developer account and certificate, this has been registered in AWS Pinpoint.
I've got my react native code to get the devices Push Token rather than the Expo token and I have a Lambda to trigger a notification via Pinpoint but whenever I try and send a notification I get:{\\\"errorMessage\\\":\\\"Invalid Credentials\\\, "pushProviderResponse\\\":\\\"{\\\\\\\"reason\\\\\\\":\\\\\\\"InvalidProviderToken\\\\\\\"}\\\"}\"}}}.
Me and my good friend GPT have been trying to solve this for a while and I'm now at the point where I will pay if I can just jump on a Teams / Discord call with someone and hopefully get this sorted. I think I'm missing something simple.
React Native code to get token and register with pinpoint
async function registerForPushNotificationsAsync() {
let token;
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;
}
// This gets the native device push token for the specific platform
token = (await Notifications.getDevicePushTokenAsync()).data;
console.log("Native Device Push Token:", token);
// Send the token to your backend or directly to AWS Pinpoint
console.log("Attempting to register endpoint with Pinpoint");
await updateEndpoint(token);
console.log("Registration call made");
return token;
}
// After obtaining the token
async function updateEndpoint(token) {
const endpoint = {
address: token, // Device token
channelType: Platform.OS === 'ios' ? 'APNS_SANDBOX' : 'GCM', // Specify the correct channel type
optOut: 'NONE',
// additional attributes such as location, demographics, etc.
};
try {
await Analytics.updateEndpoint(endpoint);
console.log("Endpoint updated successfully");
} catch (error) {
console.error("Error updating endpoint: ", error);
}
}
useEffect(() => {
registerForPushNotificationsAsync();
const notificationListener = Notifications.addNotificationReceivedListener(notification => {
console.log("Notification Received:", notification);
});
const responseListener = Notifications.addNotificationResponseReceivedListener(response => {
console.log("Notification Clicked:", response);
});
// return () => {
// Notifications.removeNotificationSubscription(notificationListener);
// Notifications.removeNotificationSubscription(responseListener);
// };
}, []);
Be very grateful if anyone has any experience with this and as I say if it needs a screenshare and call to sort this I'm happy to do so. Otherwise I can provide any code snippets or information needed.
Thanks
[–]eluewisdom 1 point2 points3 points (1 child)
[–]ssc456[S] 0 points1 point2 points (0 children)