可在Android和iOS上运行的Firebase数据消息

rak*_*los 7 push-notification apple-push-notifications android-notifications firebase

我正在向Android和iOS设备发送推送通知......我正在使用数据消息,因为我需要自定义键值对,我需要在应用程序在后台时使用它们

我的有效载荷是这样的:

{
   "to": "device token here",
   "content_available":true,
   "priority":"high",
   "data": {
      "key1": "value1",
      "key2": "value2",
      "key3": "value3",

  }
}
Run Code Online (Sandbox Code Playgroud)

这在Android上工作正常,并且通知来自iOS,通知不会通过...只有在我在有效负载中包含通知时才会通过这样:

{
   "to": "device token here",
   "notification": {
     "title": "test",
     "text": "MY Test"

   },  
   "content_available":true,
   "priority":"high",
   "data": {
      "key1": "value1",
      "key2": "value2",
      "key3": "value3",

  }
}
Run Code Online (Sandbox Code Playgroud)

第二种方法的问题是通知不再是数据消息,所以当应用程序在android的后台时我无法使用它...如何解决这个问题 - 我需要通知才能在两个平台上工作,发送数据对,理想情况下即使应用程序在后台