首页 > 解决方案 > Android 和 IOS 上的 firebase 推送通知有问题吗?

问题描述

我想通过我的服务器向 Android 和 Ios 操作系统上的用户发送通知。我使用 curl 发送消息,它看起来像这样:

$fields = array(
        'condition' => $cond,
        'priority' => 'high',
        'content_available' => true,
        'notification' => $message['data'],
        'data' => $message
    );

如果我从服务器请求中完全删除通知字段。仅发送数据字段并在 onMessageReceived() 中处理,然后我很好地收到了 Android OS 上的通知数据,但没有收到 IOS 操作系统上的通知。但是,如果我完全从我的服务器请求中添加通知字段。IOS操作系统收到好的通知,然后Android操作系统仍然收到通知但没有收到onMessageReceived()中的数据

我想要两种操作系统都能接收通知和数据的方法

标签: androidiosfirebasepush-notification

解决方案


您必须同时发送通知和数据。否则,它将无法正常工作。我不知道怎么做 php 但我已经通过 api(postman).. 这是示例

  {
     "to" : "f77ydJXI- ps:APA91bFoueDSpV0ya8CngPxOFGG4nHjTGoYMv7Bl2pbu1f1",
   "notification" : {
    "click_action" : "Notification_activity", 
    "body" : "new Symulti update !", 
    "title" : "new Symulti update !", 
    "icon" : "ic_notification" },
    "data" : {
      "body" : "First Notification backgraound",
      "title": "Collapsing A Backgraound",
      "key_1" : "Okay this is test",
      "key_2" : "4:24 pm 5/20/18"
}
}

您可以在此找到完整的示例

https://gist.github.com/Muhaiminur/f0d05f53fb2b0f5a6f3419c6514f0ca5


推荐阅读