I have a problem with silent notifications on iOS.
When my application is in background, I don't receive silent notification sent by FCM. But if I try to send directly to APNS, the notification is successfully received.
This is the JSON sent to FCM:
{
"to" : "<token>",
"priority": "high",
"content_available": true,
"data" : {
"<key>" : "<string>",
"<key2>" : "<string>"
}
}
This is the JSON sent directly to APNS:
{
"aps": {
"content-available": 1
},
"<key>": "<string>",
"<key>": "<string>"
}
I have already tried to remove the "priority" key because I saw someone saying that I shouldn't set the priority if the "content_available" is already set. It didn't work.
- I have "Push Notifications" enabled in XCode > Capabilities.
- I have "Remote notifications" checked in Background Modes in XCode > Capabilities.
- The FCM notifications are working fine when app is in foreground and sometimes when the app is in background.
Please follow the documentation for server side and make setup for json as explained over the document. I have faced similiar problem earlier and solved the issue going this doc.
you were missing notification key. which is used by apns to get notification on background.
Remove "notification" key value pair and add "content_available": true
It will look like this
This should make it a silent APNS and you need to handle with corresponding APNS delegate method.
You will need to handle this through delegates Refer this firebase documentation for details: https://firebase.google.com/docs/cloud-messaging/concept-options
I found an workaround. I put an empty value for "sound" in "notification" field and the silent notifications are delivered even when the application is in background.
My hunch is that Apple does not allow silent notifications with a 'high' priority and somehow "notification": {"sound": ""} tricks the APNS that this notification is not a silent one.
I was working on Firebase silent push notification using nodejs. When I tried below code its was working fine. When I was adding "priority": "high" and "content_available": true it was giving below error.