Search code examples
androidnotificationsapple-push-notificationsgoogle-cloud-messaging

Why is GCM and APN notifications going on some clients and not on others?


Curious case of GCM and APN in our android application.

  • We provide GCM/APN notification services to enterprises among other things.

  • In some enterprises, notification goes only on android In these cases the APNServerAPIKey and GCMServerAPIkey are different generally. It's showing mismatch sender id in apn response payload.

  • In some enterprises, notification goes only on ios

Here the apnserverapikey and gcmserverapikey are same. The response payload for both apn and gcm is succesful, but the notification is being displayed only on ios.

  • In some enterprises, we faced mismatchsenderid issue. When we made gcmkey=apnkey, this issue was resolved in some enterprises.

  • In some enterprises, we get invalid apn credentials. What's the exact difference between mismatch and invalid credentials? With whom and where are these keys being verified? What's the architectural overview of the system? We've tested if the issue is due to device's problems and tested on as modern android device as possible. It won't be sent. We've checked and turned on the notifications. Done everything. But still it won't go.

We've tried to push the notification directly using the FCM_REG_ID, it won't still be sent.

Is there a way to check if the api key has expired? If yes, please share the tip.

When the logs showed mismatchsenderid, I just made gcm=apn and the issue were resolved. But I am not exactly sure what can I do when the logs say nothing except success.

We tried to clear the cache as well.

Update: Tried to Not receiving push notifications if sending "data" (but "notification" works) payloads to GCM/FCM in iOS didReceiveRemoteNotification look at this and did a short trial.

curl -X POST \
https://fcm.googleapis.com/fcm/send \
  -H 'authorization: key=gcm_server_api_key' \
  -H 'cache-control: no-cache' \
  -H 'content-type: application/json' \
  -d '{
    "notification": {
        "body": "kanemer akheko curl"
    },
    "to" : "device_id"
}'

I'm getting success as response.

{"multicast_id":##multicastidgoeshere##,"success":1,"failure":0,"canonical_ids":0,"results":[{"message_id":"0:message_id_goes_here"}]}

This is really getting curious to me with each step.


Solution

  • There were 2 issues.

    Not receiving push notifications if sending "data" (but "notification" works) payloads to GCM/FCM in iOS didReceiveRemoteNotification

    As told here you need to put those additional headers.

    Meanwhile the app wanted "autostart" to be on (in android devices).