Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

FCM Throwing invalid-argument for IOS notifications

My project had working notifications previously and I can't trace any changes to the payload I've been sending. I've referenced the docs and can't see any issues with my payload. The exact error I am getting is

Request contains an invalid argument

let payload = {
    token : oUser.devicetoken,
    data : {
        referenceid : chatid,
        referencetype : 'chat',
        referencename : oSender.displayname,
        receiverid : userid,
        type : 'message',
        notificationid : res,
        title : title,
        body : `${oSender.displayname} : ${body}`
    },
    android : {
        priority : 'high'
    },
    apns : {
        payload : {
            aps : {
                'content-available' : 1
            }
        },
        headers : {
            'apns-push-type' : 'background',
            'apns-priority' : '5',
            'apns-topic' : 'llc.attebyte.partyme'
        }
    }
};

My current payload:

After taking a fresh look at the Apple docs for notifications I noticed that I should be using content-available. I had previously been using contentAvailable: true (and it was working). Neither one is working anymore.

There are multiple questions regarding this problem already. This one being the best I've found: firebase cloud messaging Request contains an invalid argument

I verified that the token is correct by sending the device a test notification from the firebase console. I don't think I should be hitting the size limit of 4kb, the message I am sending for testing is something along the lines of 'test' or 'hello' (also the issue is IOS specifi). I've also verified that the headers I am sending are current with the Apple docs.

I can't figure out any differences that would cause notifications to stop working within the last week or so. I know they were working then and I've gone through my Github history to verify the payload hasn't changed (besides my change to content-available I made today while testing.)

like image 231
Tristan Avatar asked Apr 12 '21 02:04

Tristan


People also ask

Does FCM work on iOS?

Stay organized with collections Save and categorize content based on your preferences. For Apple client apps, you can receive notification and data payloads up to 4000 bytes over the Firebase Cloud Messaging APNs interface.

Does FCM token change iOS?

"The registration token may change when: The app is restored on a new device. The user uninstalls/reinstall the app.

What is FCM token in iOS?

The app request APNs for a device token. Then it sends that device token to FCM (Firebase Cloud Messaging) and in return receives FCM device token. Now this token can be send to your server/cloud function which is keeping track of all these unique device tokens which will be used to send notification.

How do I use FCM for push notifications?

For sending FCM notification payload you can use Firebase Cloud Messaging Tool in firebase console. And click on Send your first message. Then enter the Title and body field. If you wish to send it to a particular device then click on Send test message and enter the FCM registration token.


1 Answers

While Google takes its time to fix this, we could successfully send silent notifications using the legacy app server protocols:

https://firebase.google.com/docs/cloud-messaging/send-message#send-messages-using-the-legacy-app-server-protocols

The endpoint we are using is https://fcm.googleapis.com/fcm/send.

Here you can find the message structure (note that is quite different from the current API):

https://firebase.google.com/docs/cloud-messaging/http-server-ref

And here how to authorize the requests:

https://firebase.google.com/docs/cloud-messaging/auth-server#authorize-http-requests

Hope it helps while we wait for a definitive fix.

like image 114
Gabriel Diéguez Avatar answered Oct 24 '22 20:10

Gabriel Diéguez