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

时间:2016-12-23 14:12:00

标签: ios cordova notifications cordova-plugins firebase-cloud-messaging

我正在使用此插件与cordova:cordova-plugin-fcm来发送通知。

它适用于Android。

问题出在iOS上,当应用处于前台时,通知就会到来。但是当应用程序关闭或在后台时,通知不会显示在通知栏中,但是当我打开应用程序时,我可以看到通知到达并且我生成的弹出窗口被打开。

但我真的需要通知在锁定屏幕和通知栏中显示。

这是我发送给Firebase API的内容:

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

在身体上我发送了这个:

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

我也尝试过使用"priority": "high"并获得相同的结果。

通知到达,但只会在我打开应用时显示。我甚至没有在通知栏或锁屏中看到它。

此外,我尝试在正文中添加"aps"属性,其中包含所有信息..不起作用。

我希望有人可以为此提供一些启示......

PS: iOS v10.1.1

PS2:适用于所有Android设备。

我已经从社区中读到了一些答案,但似乎没有用:

Firebase API is not sending push notifications when using the API

iOS not receiving Firebase Push Notification sent through the API

感谢您的时间。

2 个答案:

答案 0 :(得分:3)

让您在console.firebase.google.com上传您的开发APNs证书,

将您的APNs证书上传到Firebase。如果您还没有APNs证书,请参阅配置APNs SSL证书。

在Firebase控制台中的项目内,选择齿轮图标,选择“项目设置”,然后选择“云消息传递”选项卡。 选择开发证书,生产证书或两者的“上载证书”按钮。至少需要一个。 对于每个证书,请选择.p12文件,并提供密码(如果有)。确保此证书的软件包ID与应用程序的软件包ID相匹配。选择保存。

您可以参考链接https://firebase.google.com/docs/cloud-messaging/ios/client

答案 1 :(得分:0)

我有同样的问题, 首先,你需要使用“body”而不是“text”; 对于优先级,您应始终使用“高”或“正常”,对于推送,默认值应该高。 如果您忘记在Json字符串的通知对象中使用“title”和“body”键,iOS显然不会将通知添加到通知列表中。

如果需要某些自定义值,请添加具有自定义值的数据对象。像这样:

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

所以尝试这样的事情:

{
  "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"
}

结合数据对象:

     {
          "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"
      }

我希望这有帮助,它为我做了