简体   繁体   中英

cordova, Firebase, FCM Plugin - Not showing notifications in notification bar on iOS

I'm using this plugin with cordova: cordova-plugin-fcm to get notifications working.

It works good on Android.

Problem is with iOS, when the app is in foreground the notifications arrives. But when the app is closed or in background, the notification doesn't show in notification bar, but when I open the application I can see the notification arriving and the popup I generate, gets opened.

But I really need to notification to show in lock screen and in the notification bar.

This is what I'm sending to Firebase API:

/ POST to https://fcm.googleapis.com/fcm/send

And in the body I'm sending this:

{
  "to" : <USER_TOKEN>,
  "alert":"Test",
  "notification": {
    "alert":"Test test",
    "title": "Notification test",
    "text": "Testing notification text"
  },
  "priority": 10,
  "content_available": true
}

I've also tried with "priority": "high" and get the same results.

The notification arrives, but it only shows when I open the app. I don't even get it in the notification bar or lock screen.

Also I tried adding the "aps" property in the body, with all the information inside.. doesn't work.

I hope someone can throw some light into this..

PS: iOS v10.1.1

PS2: Works good on all android devices.

I've already read some answers from the community but doesn't seem to work:

Firebase API is not sending push notifications when using the API

iOS not receiving Firebase Push Notification sent through the API

Thanks for your time.

have you Upload your Development APNs certificate on console.firebase.google.com,

Upload your APNs certificate to Firebase. If you don't already have an APNs certificate, see Provisioning APNs SSL Certificates.

Inside your project in the Firebase console, select the gear icon, select Project Settings, and then select the Cloud Messaging tab. Select the Upload Certificate button for your development certificate, your production certificate, or both. At least one is required. For each certificate, select the .p12 file, and provide the password, if any. Make sure the bundle ID for this certificate matches the bundle ID of your app. Select Save.

you can refer link https://firebase.google.com/docs/cloud-messaging/ios/client

I had the same problem, First of all, you need to use "body" instead of "text"; For priority you should always use "high" or "normal", for pushnotifications the default value should be high. If you forget to use the "title" and "body" key in the notification object of your Json string, iOS wont add the notification to the notificatios list apparently.

If you want some custom values, then add a data object with custom values. like this:

    "data":{
     "data1":"value1",
     "data2":"value2"
  }

So try something like this:

{
  "to" : <USER_TOKEN>, //or /topics/<topicname> or /topics/all"
   "notification": {
    "title": "Notification test",
    "body": "Testing notification text"
  },
      "priority": high,
      "sound":"default", //not using this one wont make your iOS device use sound
      "click_action":"FCM_PLUGIN_ACTIVITY",
      "icon":"fcm_push_icon"
}

Combined with data object:

     {
          "to" : <USER_TOKEN>, //or /topics/<topicname> or /topics/all"
          "notification": {
            "title": "Notification test",
            "body": "Testing notification text"
          },
          "data":{
             "data1":"value1",
             "data2":"value2"
          },
          "priority": high,
          "sound":"default", //not using this one wont make your iOS device use sound
          "click_action":"FCM_PLUGIN_ACTIVITY",
          "icon":"fcm_push_icon"
      }

I hope this helps, it did for me

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM