Open SephReed opened 5 years ago
SDK error codes aren't really hierarchical. They just look that way because they have the general form <service prefix>/<error code>
. Plus I don't think the FCM service currently sends enough details in the error to distinguish between above 4 cases. So perhaps what we need a set of new error codes.
But we'll want the FCM backend service to support these first.
Is there anywhere I should re-post this issue? It's has become a huge blocker for me.
This doesn't exactly match your case but see if it helps-
I was facing the same issue. Here is how I fixed it (iOS specific, android was working out of the box)-
async componentDidMount() {
this.checkPermission();
this.createNotificationListeners();
}
4.
async checkPermission() {
const enabled = await firebase.messaging().hasPermission();
if (enabled) {
this.getToken();
} else {
this.requestPermission();
}
}
async requestPermission() {
try {
await firebase.messaging().requestPermission();
// User has authorised
this.getToken();
} catch (error) {
// User has rejected permissions
console.log('permission rejected');
}
}
async getToken() {
try {
const enabled = await firebase.messaging().hasPermission();
if (!enabled) {
await firebase.messaging().requestPermission();
}
const fcmToken = await firebase.messaging().getToken();
if (fcmToken) {
console.log("got token");
console.log('fcm token:', fcmToken); //-->use this token from the console to send a post request via postman
this.setState({ fcmToken });
return fcmToken;
}
} catch (error) {
console.warn('notification token error', error);
}
}
5.
async createNotificationListeners() {
/*
* Triggered when a particular notification has been received in foreground
* */
this.notificationListener = firebase.notifications().onNotification((notification) => {
const { title, body } = notification;
this.showAlert(title, body);
});
/*
* If your app is in background, you can listen for when a notification is clicked / tapped / opened as follows:
* */
this.notificationOpenedListener = firebase.notifications().onNotificationOpened((notificationOpen) => {
const { title, body } = notificationOpen.notification;
this.showAlert(title, body);
});
/*
* If your app is closed, you can check if it was opened by a notification being clicked / tapped / opened as follows:
* */
const notificationOpen = await firebase.notifications().getInitialNotification();
if (notificationOpen) {
const { title, body } = notificationOpen.notification;
this.showAlert(title, body);
}
/*
* Triggered for data only payload in foreground
* */
this.messageListener = firebase.messaging().onMessage((message) => {
//process data message
console.log(JSON.stringify(message));
});
}
For a more detailed setup/citation- https://medium.com/@anum.amin/react-native-integrating-push-notifications-using-fcm-349fff071591
I'll have to try this out. I'm currently using nativescript, so it'll end up being a bit different, but I should still be able to apply a lot of this logic. Thank you very much!
@SephReed, where you found that registration token can expire? I can't find it in the documentation.
Whatever it was that was wrong, fixed itself. Didn't change anything, just started working. My guess is that it was the messaging/registration-token-not-registered/apns-invalid
error.
@sgrigorev https://firebase.google.com/docs/cloud-messaging/send-message#admin_sdk_error_reference
ctrl+f messaging/registration-token-not-registered
I don't know the exact contents of the raw API response, but implementing https://github.com/firebase/firebase-admin-node/issues/756 might be helpful here.
I'm not sure if this is the correct repo for this pr, but it is the codebase I'm working in.
I'm currently running into the error
messaging/registration-token-not-registered
, and found the documentation on it:Given the documentation above, it would seem this error is quite broad, requiring an in-depth understanding of "app registration to FCM," "APNS tokens," "Expiration," and mis-configured apps. I'm pretty uncertain where to start in terms of approaching it.
As a Feature Request, I think it would be really, really helpful if this one mega error was instead a few small ones, for instance:
messaging/registration-token-not-registered/apns-invalid
messaging/registration-token-not-registered/app-not-configured
messaging/registration-token-not-registered/expired
messaging/registration-token-not-registered/app-unregistered