How should I send notifications with push notifications thru FCM for both Android and iOS?

Viewed 27

I am trying to send notifications to both Android and iOS devices using FCM. The front end was coded with Flutter. I am working with Typescript/NestJS at the back end. For some reason, iOS devices receive all the notifications with a push notification/pop-up but Android devices sometimes don't. Strangely, the notifications ALL arrive at the test device INBOXES. It's just that sometimes, Android devices do not show a pop-up/push notification.

Targeting users thru a Firebase topic works as expected: push notifications do arrive for Android and iOS. I do have to find and filter out the users to target before sending the target device IDs to FCM. I am confident my filters are correct. The notifications arrive in the app inbox for both Android and iOS after my filtering. Also, changing the device ID/token in my database causes an error from FCM:

{"code":"messaging/registration-token-not-registered","message":"Requested entity was not found."}

If I revert the data to its original values, the app runs fine. I've checked and compared the data I pass to Node.js' FCM module and it looks fine. Here, messaging is an instance of firebaseAdmin.messaging().

param = {
    "android": {
        "data": {
            "id": "67bcd478-f643-4c9e-848a-be354a6b85d4",
            "icon": "default",
            "title": "Test",
            "body": "Direct From Playground"
        }
    },
    "apns": {
        "payload": {
            "aps": {
                "id": "67bcd478-f643-4c9e-848a-be354a6b85d4",
                "icon": "default",
                "title": "Announcements",
                "body": "Direct From Playground",
                "alert": {
                    "title": "Announcements",
                    "body": "Direct From Playground"
                }
            }
        }
    }
}

messaging.sendMulticast({
    tokens: value as string[],
    ...param,
});

Again, the code above sometimes successfully triggers push/pop-up notifications on Android devices but ALWAYS on iOS. Could this be a problem for the front-end handling of my data? Am I missing some parameters?

0 Answers
Related