2

I send this to Firebase:

{
    "to" : "/topics/12344",
    "priority" : "high",
    "data" : {
      "c" : "sometext",
      "t" : "someothertext"
    },
  }

On Android I can create custom notification using the "data" payload with accessing its objects. I don't have to send the message title and body because I create custom text. This works even if the app is closed.

On iOS I can access the custom data using:

func messaging(_ messaging: Messaging, didReceive remoteMessage: MessagingRemoteMessage) {
    print("Received data message: \(remoteMessage.appData)")
}

But it only prints if the the app is opened, not when closed. If I send the "notification array" to Firebase, it creates a notification when the app is closed, but I am not able to access the custom payload.

My question: How can I access the custom payload on iOS when the app is closed and create a notification?

Francis
  • 343
  • 2
  • 5
  • 16

1 Answers1

0

If app is closed or die , only Notification can be passed to the app https://firebase.google.com/docs/cloud-messaging/concept-options

When in the background, apps receive the notification payload in the notification tray, and only handle the data payload when the user taps on the notification.

When in the foreground, your app receives a message object with both payloads available.

 {
    "to" : "APA91bHun4MxP5egoKMwt2KZFBaFUH-1RYqx...",
    "notification" : {
      "body" : "great match!",
      "title" : "Portugal vs. Denmark",
      "icon" : "myicon"
    },
    "data" : {
      "Nick" : "Mario",
      "Room" : "PortugalVSDenmark"
    }
  }