skip to Main Content

So I’m using the firebase push notification in my app. Notification is working fine with the following payload,

{
    "to": "cMXdSK_ud0LpqMoju85FvT:APA91bFMke92QR1IvcLeLhG5XrvwcE0OfSLGpJW1ds9-FFDornoeorMlKOn6IEtDYsuvwlRrwJnHJy0BPl_udcbqac39WF1cllsEV3l------------",
    "notification": {
        "title": "10-inch Aggretsuko Rage #24 (Jumbo Size)",
        "subtitle": "Test notification Krunal"
    }
}

But when I used the same payload format that mentions in the apple documentation then the notification is sent successfully but not received on the device. Check this payload,

{
    "to": "cMXdSK_ud0LpqMoju85FvT:APA91bFMke92QR1IvcLeLhG5XrvwcE0OfSLGpJW1ds9-FFDornoeorMlKOn6IEtDYsuvwlRrwJnHJy0BPl_udcbqac39WF1cllsEV3l------------",
   "aps" : {
      "alert" : {
         "title" : "10-inch Aggretsuko Rage #24 (Jumbo Size)",
         "subtitle" : "Test notification Krunal",
      },
      "category" : "GAME_INVITATION"
   },
   "gameID" : "12345678"
}

Can someone please explain what’s the actual problem with the above payload I want to use that in my flutter app. When I used the notification keyword in the payload that create a problem in the flutter android app. Can someone please help me to solve this problem?

2

Answers


  1. What is happening here is that you’re using FCM messages. When you do this, you actually send the notification payload to Firebase. Firebase then transforms this payload into the appropriate payload format for iOS or Android or web and then sends it to the respective messaging service.

    For the payload that you’ve built looking at the Apple documentation to work you would have to send it to APNS.

    You can specify Apple specific keys in your FCM message as-well. See the documentation here.

    You can use the ApnsConfig object to specify things that are specific to Apple devices.

    To set options specific to Android devices you may use the AndroidConfig object.

    Now, coming to the problem you mention with the Android app, looking at the ‘to’ field in your payload, I must assume you are using one of the legacy APIs (XMPP Server Protocol or Legacy HTTP Server Protocol) instead of the ones I have suggested above. In this case, are you sure you have updated the recipient in the ‘to’ field when sending the payload? If yes, then could you please explain the problem you are seeing in your Android app when using the FCM specific payload.

    Login or Signup to reply.
  2. I think the problem is that Firebase wants a different JSON structure than the proprietary data structure that actually ends up being used on Apple systems. Firebase is doing the conversion for you from your first example.

    Your second example is the kind of payload the Apple Simulator can make use of xcrun simctl push so it is still helpful for local testing and development.

    The final part of your question about why it is a problem for Android I am not sure about. But I wonder whether you supplied the wrong FCM token because that might encode the intended platform type within in making it incompatible for Android delivery. Firebase seems to always know the right platform specific way to deliver a push message, whether it is Android or iOS, so it must keep a track of that via the FCM token.

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search