简体   繁体   English

cordova,Firebase,FCM插件 - 未在iOS上的通知栏中显示通知

[英]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. 我正在使用这个带有cordova 的插件cordova-plugin-fcm来获取通知。

It works good on Android. 它适用于Android。

Problem is with iOS, when the app is in foreground the notifications arrives. 问题出在iOS上,当应用程序处于前台时,通知会到达。 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: 这是我发送给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. 我也尝试过"priority": "high"并获得相同的结果。

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. 此外,我尝试在正文中添加"aps"属性,里面的所有信息都不起作用。

I hope someone can throw some light into this.. 我希望有人可以对此有所启发..

PS: iOS v10.1.1 PS: iOS v10.1.1

PS2: Works good on all android devices. PS2:适用于所有Android设备。

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 使用API​​时,Firebase API不会发送推送通知

iOS not receiving Firebase Push Notification sent through the API iOS未通过API发送Firebase推送通知

Thanks for your time. 谢谢你的时间。

have you Upload your Development APNs certificate on console.firebase.google.com, 你有没有在console.firebase.google.com上传你的开发APNs证书,

Upload your APNs certificate to Firebase. 将您的APNs证书上传到Firebase。 If you don't already have an APNs certificate, see Provisioning APNs SSL Certificates. 如果您还没有APNs证书,请参阅配置APNs SSL证书。

Inside your project in the Firebase console, select the gear icon, select Project Settings, and then select the Cloud Messaging tab. 在Firebase控制台的项目内,选择齿轮图标,选择“项目设置”,然后选择“云消息传递”选项卡。 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. 对于每个证书,请选择.p12文件,并提供密码(如果有)。 Make sure the bundle ID for this certificate matches the bundle ID of your app. 确保此证书的软件包ID与应用程序的软件包ID相匹配。 Select Save. 选择保存。

you can refer link https://firebase.google.com/docs/cloud-messaging/ios/client 您可以参考链接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"; 我有同样的问题,首先,你需要使用“body”而不是“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. 如果您忘记在Json字符串的通知对象中使用“title”和“body”键,iOS显然不会将通知添加到notificatios列表中。

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 我希望这有帮助,它对我有用

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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