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.
@spacitron fcm is firebase cloud messaging, so he does ;) do not send body , title , link , inside the notification otherwise user will get visible notifications . if you want to send totally silent notification then add some custom parameter in notification or keep it blank .
For Apple client apps, you can receive notification and data payloads up to 4000 bytes over the Firebase Cloud Messaging APNs interface. To write your client code in Objective-C or Swift, we recommend that you use the FIRMessaging API.
Silent push notifications are simply notifications that mobile app users receive without any pings, alerts, or interruptions to the user. They arrive on the mobile device and sit in the notification tray until read or dismissed.
I am new to iOS and i struggled with silent push notification,googled a lot and got stuck. Will iOS awake my app when i receive silent push notification when app is not launched(i.e when app is removed from app switcher). this method is called and works fine when app is in foreground and background.
Remove "notification" key value pair and add "content_available": true
It will look like this
{ "to" : "...", "priority": "high", "content_available": true, "data" : { .... } }
This should make it a silent APNS and you need to handle with corresponding APNS delegate methods.
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.
{ "to" : "...", "priority": "high", "notification": { "sound": "" }, "data" : { .... } }
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With