IrApp
IrApp

Reputation: 1843

FCM Firebase push notification Android/iOS

I'm using FCM to send notifications for a project in booth plattforms, iOS and Android. Following are the payloads I'm sending:

{ 
  "to":"user_key",
  "priority":"high",
  "content_available":true,
  "mutable_content":true,
  "data":{
        "body":"test"
  }
}

After reading the Firebase documentation, the behaviour when sending notification and data payload through FCM is:

iOS

Android

The thing is:

For Android I want to avoid to pass notification_payload in order to receive data when app is in background (in this way onMessageReceived() will be called). But then, I won´t receive notifications in iOS.

Help/Suggestions appreciated.

Upvotes: 5

Views: 2666

Answers (1)

Onix
Onix

Reputation: 692

Server should use different json structures for IOS and Android push request. For example:

Android:

[data] => Array
        (
            [title] => Test
            [message] => Message
        )

IOS:

[notification] => Array
        (
            [title] => Title
            [body] => Body
            [sound] => 1
            [vibrate] => 1
        )

[data] => Array
        (
            [custom_key] => custom_value
        )

You can edit it according to your task.

Upvotes: 1

Related Questions