FirebaseMessaging.onBackgroundMessage is not invoked when my app is on background in flutter , its happening only in Ios devices
Asked Answered
G

4

10

I Am making an app which has push notification Property app is working when we hit notification on the foreground , but when app is on background my _backgroundHandler() method is not invoking, its happening only In IOS App Only

Grotesquery answered 6/7, 2022 at 10:53 Comment(0)
A
8

also struggle this issue.

set payload as below. mutable-content make sense.

apns: {
    payload: {
        aps: {
            'mutable-content': 1, 
            'content-available': 1
        }
    }
}

https://github.com/firebase/flutterfire/issues/9381#issuecomment-1229167020

set "mutable-content:1" in payloads, iOS passes the notification to our notification service app extension.

For more information APNs payload, see the following links:

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

Accountable answered 23/9, 2022 at 13:39 Comment(1)
'content-available': 1 did the trick for meAutobus
M
5

Enable background fetch, background processing and remote notification in Xcode preview

Edit

Add mutable key to payload

{ "to": "dWdhfjfjdbzbmjJ5....", "content_available": true, "mutable_content": true,

"data": { "message": "some msg", "mediaUrl": "image url here" },

"notification": { "body": "notification msg", "sound": "default" } }

EDIT


var payload = {
    notification: {
      title: `msg title here`,
      body: `msg body here`
      }`,
    },
    // Set Android priority to "high"
    android: {
      priority: "high",
    },
    // Add APNS (Apple) config
    apns: {
      payload: {
        aps: {
          contentAvailable: true,
        },
      },
      headers: {
        //"apns-push-type": "background", // This line prevents background notification
        "apns-priority": "10",
      },
    },
    token: "dnqTQVso60GfnnuOjHv8_e:APA91bElr-K3xkQMdYHX8VMrasdfasdfkjhasidfgjn"
 };
Millen answered 6/7, 2022 at 11:9 Comment(20)
Already did it, but same problem exists , I am sucking on it for 5 days I did not find any solution of thatGrotesquery
Also did you add permission to allow sound alert and badge?Millen
yes i also allowedGrotesquery
All other push notifications are working?Millen
yes all working in forground alsoGrotesquery
in android, all state notifications are working , means foreground,background,and also kill stateGrotesquery
sory to say but already added this in my payload but same result no message received in background handlerGrotesquery
Try setting priority too ib apnsMillen
from app developer??Grotesquery
firebase.google.com/docs/cloud-messaging/…Millen
"apns-priority":"5" did it like this but same resultGrotesquery
i have an update in my ios mobile is this the issue ??Grotesquery
No an update available cannot be an issue. Should be some settings that's missing. Are you getting notification when the app is in foregroundMillen
yes i getting the notification when app is forgroundGrotesquery
And if i used content_available true it's showing 2 notifications first firebase server then it comes to my modified notification (means if I used content_available true notification is coming in the background but first notification shows silently then my original notification come with imageGrotesquery
Added a payload.. Please try that oneMillen
already tried to added the paylod and check same result coming 2 notificationGrotesquery
first silently (Like when we send through direct firebase messaging server ) and second one is my modified notficationGrotesquery
Same problem with small body , notification also coming twiceGrotesquery
Same issue here, all of a sudden it is not working. When I then opens the app the notifications arrives via local notifications packageGona
D
1

Adding this in my payload solved my issue:

apns: {
    payload: {
        aps: {
            'mutable-content': 1, 
            'content-available': 1
        }
    }
}
Dump answered 14/1, 2023 at 16:56 Comment(0)
A
0

I have face this issue too.

@goza's answer should been accepted.

This is my sending json.

{
   "message":{
      "token":"fcm token",
      "notification":{
         "title":"NotifyTitle",
         "body":"NotifyBody"
      },
      "data":{
         "title":"DataTitle",
         "body":"DataBody"
      },
      "apns":{
          "payload":{
             "aps":{
                "content-available":1
             }
          }
       }
   }
}
Astrogeology answered 13/10, 2022 at 7:48 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.