Fcm Remote Notifications Payload for iOS and Android

Behavior of localized push notifications using FCM

So experimentally I have found out that if you send in one notification loc_keys and normal title and body, if the application has the translation, it shows the localized notification and if not, it fallbacks to the normal title and body properties.

FCM data messages not being received by iOS Simulator or physical device

Original answer (more general/ useful to more people):

FCM does not work on the iOS simulator, so thats half the question solved. For physical devices, take a look at some debugging steps I wrote in detail on a library I work on.

There are multiple ways push notification can go wrong on iOS. When you say: the app never receives, do you mean your Flutter application doesn't get the message? Your device could still be receiving them.

  • Open Console.app on your mac, and start the logging for your physical device. Filter for dasd process, and you can see push notification related logs to see if your device rejected the push notification and did not send it to your app. Most likely, its a problem with how you structured your message.
  • You can also try to debug the didReceiveRemoteNotification method on the iOS side inside the Flutterfire firebase_messaging iOS code. That would mean the message is received by the app.


Let me answer each question/ concern (3) specifically:

  1. My iOS physical device receives push notifications, but only when the app is in the background or closed but NOT when in the foreground.

So you want to show notifications in the foreground? You need to implement userNotificationCenter(_:willPresent:withCompletionHandler:), for example, in Swift:

    public func userNotificationCenter(_ center: UNUserNotificationCenter, willPresent notification: UNNotification, withCompletionHandler completionHandler: @escaping (UNNotificationPresentationOptions) -> Void) {
if #available(iOS 14.0, *) {
completionHandler(.banner)
} else {
completionHandler(.alert)
}
}

To help you a little more here, you need to set your delegate. Place a breakpoint in the method implemented above to see it's actually being called.

  • In Swift: UNUserNotificationCenter.current().delegate = self;
  • In Objective-C: UNUserNotificationCenter.currentNotificationCenter.delegate = self;

  1. Further, it does NOT receive any fcm message (data) notifications at all such as messages with only data and no notification title/body i.e. VoIP status message.

If you do not set the notification field, then you need to set the priority to 5, push type to background, and contentAvailable to true. Unfortunately, you are using the headers field in firebase wrong. The apns object should look like the following, where headers is inside apns, since these are apns specific headers:

    apns: {
headers: {
"apns-push-type": "background",
"apns-priority": "5", // Must be `5` when `contentAvailable` is set to true.
"apns-topic": "io.flutter.plugins.firebase.messaging", // bundle identifier
},
payload: {
aps: {
category: "NEW_MESSAGE_CATEGORY",
contentAvailable: true,
}
}
}

If the message was structured wrongly, you could still get an error on the device, for example, telling you that the priority was 10 (it defaults to 10 if it is not set). Because background messages (no notification) won't be delivered as per the documentation, in Console.app you should see:

CANCELED: com.apple.pushLaunch.com.example.my-example-app-bundle-id:3D8BB6 at priority 10 <private>!

Additionally, the notification’s POST request should contain the apns-push-type header field with a value of background, and the apns-priority field with a value of 5. - Pushing Background Updates to Your App


  1. While debugging, if the iOS app is in foreground/background and a test notification or a valid VoIP call (FCM data message) is sent to the device, the app never receives or (nor does the required breakpoint hit either). What can cause the app/iOS not to receive these FCM messages?

This is the same as #2.

FCM differences between Android and iOS about data messages

On 16/02/14, Firebase added compliance with the "mutable-content" key. So that solved my problem and, I think, many people's problems.

Personal thinking:

I consider that 6 months late for this feature is really too much. I hope that future releases'll be up to date with iOS (as well as Android) releases.



Related Topics



Leave a reply



Submit