Have a data message for Android and normal notification for IOS in single FCM request

Viewed 297

Currently, I have different ways to handle notifications depending on if the system is Android or IOS, for Android, I send a data-only notification and create a local notification from it.

For IOS, since data-only notifications have no guarantee that they will be retrieved if the app is closed, I send a normal notification.

What I'm trying to do is having both notifications using the same FCM API call, here is my current json:

{
    "data": {
        "click_action": "FLUTTER_NOTIFICATION_CLICK",
        "d": "my_data",
    },
    "apns": {
        "headers": {
            "apns-priority": "10"
        },
        "payload": {
            "aps": {
                "alert": {
                    "title": "my title",
                    "body": "my body"
                }
            }
        }
    },
    "priority": "high",
    "registration_ids": [...],
    "time_to_live":86400
}

So, what I expected from this request is that for android it would create a data only notification using:

{
    "data": {
        "click_action": "FLUTTER_NOTIFICATION_CLICK",
        "d": "my_data",
    }
}

And for IOS, it would create a normal notification using:

{
    "notification": {
        "title": "my title",
        "body": "my body",
    }
}

This works for Android, but I don't receive this notification as a normal notification on IOS.. Shouldn't the apns payload be used for IOS in this case?

0 Answers
Related