'FCM push notifications only works on Android, but only the message is sent to both Android and IOS

In our backend we are raising events for creating push notifications and message only through FCM (separated).

One "message"(data only) for customer and the clients related to order for updating it on screens etc, and one push notification for customer.

The thing is that, android receives both push and message, but IOS only receives the message, and not the push notification.

When I send push notifications directly to an Iphone device through tests from our .NET backend (which implements the Firebase messaging service, which also uses the same events that are raised), the Iphone device receives the push notification.

We are using app distribution and the app is built with react-native. Our backend .NET, using firebase-admin SDK.

Things we have noticed are:

  • Uninstall and install the app again makes the notification work but only once then it stops working.

  • When the customer app is on the same device as the other app that "triggers" the updates on an order if it´s updated, the notification is received to the same device in the customer app.

Code:

Message message = new Message
{
    Token = token,
    Notification = new Notification
    {
        Title = title,
        Body = body
    },
    Android = new AndroidConfig
    {
        Data = data as IReadOnlyDictionary<string, string>,
        Priority = Priority.High,
        TimeToLive = TimeSpan.FromMinutes(ttl),
        Notification = new AndroidNotification
        {
            ChannelId = "default"
        }
    },
    Apns = new ApnsConfig
    {
        Aps = new Aps
        {
            ContentAvailable = true,
            CustomData = dataToStringObject
        }
    }


Solution 1:[1]

You need to send notification key in the json for IOS. then only IOS device will receive the notification.

Solution 2:[2]

When you set "ContentAvailable: true" without alert field, fcm send silent push in ios.

The background notification flag. To perform a silent background update, specify the value 1 and don’t include the alert, badge, or sound keys in your payload.

https://developer.apple.com/documentation/usernotifications/setting_up_a_remote_notification_server/generating_a_remote_notification

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Dipakk Sharma
Solution 2 ali