firebase / firebase-admin-dotnet

Firebase Admin .NET SDK
https://firebase.google.com/docs/admin/setup
Apache License 2.0
367 stars 131 forks source link

Background Notification not being sent to iOS app #216

Closed crash-her closed 4 years ago

crash-her commented 4 years ago

When I execute the below code my app does not get the background notification but the batchResponse is a success. Before switching to Firebase we were using Apples APNS protocols to trigger the background notifications and it works flawlessly.

var fireMessages = new List<FireMessage>()
{
    new FireMessage()
    {
        Data =  new Dictionary<string, string>(){{"type","update"}},
        Token = token,
        Apns = new ApnsConfig
        {
            Headers = new Dictionary<string, string>
            {
                {"apns-push-type", "background"},
                {"apns-priority", "5"}
            },
            Aps = new Aps
            {
                ContentAvailable = true
            }
        }
    }
};

var firebaseApp = FirebaseApp.GetInstance(instanceName);

var batchResponse = await FirebaseMessaging.GetMessaging(firebaseApp).SendAllAsync(fireMessages);

the generated body is

{
    "message": {
        "token": "fO7t3fyX-k3sgEk5Mtv6O-:...",
        "data": {
            "type": "activity_updates"
        },
        "apns": {
            "headers": {
                "apns-push-type": "background",
                "apns-priority": "5"
            },
            "payload": {
                "aps": {
                    "content-available": 1
                }
            }
        }
    },
    "validate_only": false
}
hiranya911 commented 4 years ago

Are there any errors indicated in the returned BatchResponse?

crash-her commented 4 years ago

No I receive a success response.

hiranya911 commented 4 years ago

Please reach out to Firebase Support and provide your project ID and token information. They can help you sort it out. If there are no errors in the SDK-end that means the message was successfully handed off to FCM backend service for delivery.

crash-her commented 4 years ago

when i use the legacy API i send it a JSON of

{
  "data":{
      "type":"activity_updates"
  },
  "priority": "high",
  "content_available": true,
  "to":"dCw-..."
}

that works

Gekidoku commented 1 year ago

I have the same issue and with the legacy api being depreciated soon this should really be fixed. It works on android for me. but on ios i dont recieve a message unless i also include the notification field.

Gekidoku commented 1 year ago

https://dotnetfiddle.net/iwIGCu Here is how im sending the message