【问题标题】:FCM rich push notification payload for iOS适用于 iOS 的 FCM 丰富推送通知负载
【发布时间】:2017-07-20 18:43:51
【问题描述】:

我在我的项目中使用FCM。它具有丰富的类型推送通知。我尝试修改大多数可能的方式来从FCM 获得推送。我收到了来自FCM 的普通推送,而不是图片。

我还使用push try 与 APNS 相同的编码进行检查。我得到了推送通知的预期设计。

这是我的APNS 有效载荷

{
  "aps": {
     "alert": "Enter your message",
     "badge": 1,
     "sound": "default",
     "content-available": 1,
     "mutable-content": 1
  },
  "mediaUrl": "https://upload.wikimedia.org/wikipedia/commons/thumb/2/2a/FloorGoban.JPG/1024px-FloorGoban.JPG"
}

这里FCM有效载荷

{
   "to": "dWB537Nz1GA:APA91bHIjJ5....",
   "data":
   {
      "message": "Offer!",
      "mediaUrl": "https://upload.wikimedia.org/wikipedia/commons/thumb/2/2a/FloorGoban.JPG/1024px-FloorGoban.JPG"
   },
   "notification":
   {
      "body": "Enter your message",
      "sound": "default",
      "content-available": 1,
      "mutable-content": 1
   }
}

我也需要分类more details about payload in FCM

我是否遗漏了 fire-base 控制台中的任何设置,或者是来自有效负载的设置。

【问题讨论】:

    标签: ios firebase push-notification apple-push-notifications firebase-cloud-messaging


    【解决方案1】:

    FCM 负载中的 mutable-contentcontent-available 不正确。它的格式应为mutable_contentcontent_available。两者都是 boolean 并且还必须在 notification 参数之外。像这样:

    {
       "to": "dWB537Nz1GA:APA91bHIjJ5....",
       "content_available": true,
       "mutable_content": true,
       "data":
       {
          "message": "Offer!",
          "mediaUrl": "https://upload.wikimedia.org/wikipedia/commons/thumb/2/2a/FloorGoban.JPG/1024px-FloorGoban.JPG"
       },
       "notification":
       {
          "body": "Enter your message",
          "sound": "default"
       }
    }
    

    对于FCM中category的对应物,你应该使用click_action

    与用户点击通知相关的操作。

    对应于 APNs 负载中的 category

    【讨论】:

    • @AL。这是正确的 FCM 有效载荷吗?我的意思是为什么消息和正文是分开的?不能同时在通知中或同时在数据中吗?我觉得将通知的标题和消息放在单独的 { } 中是不合适的
    • @Balanced 它是一个有效的负载。但是,您确实提到的也是有效的。这一切都取决于您的用例。
    • 我们可以在有效载荷中传递字典吗? “to”:“设备令牌”,“content_available”:true,“notification”:{},“data”:{“payload”:{“dataa”:{“btn_action”:“一些文本”,“lock_mac”: "0Some text", "device_type" : "iOS", "some key" : "Some text" } } } }
    • @Developer data 消息负载迎合自定义数据。所以是的。只要确保你处理得当。干杯!
    • AL。 func application(_ application: UIApplication, didReceiveRemoteNotification userInfo: [AnyHashable: Any], fetchCompletionHandler completionHandler: @escaping (UIBackgroundFetchResult) -> Void) userInfo["payload"] as? [String:Any] 在上述函数中始终为零
    【解决方案2】:

    这对我有用。接受的答案似乎有一些不必要的信息。

    {
      "to" : "devicekey OR /topics/sometopic",
      "mutable_content": true,
      "data": {
        "mymediavideo": "https://myserver.com/myvideo.mp4"
      },
      "notification": {
        "title": "my title",
        "subtitle": "my subtitle",
        "body": "some body"
      }
    }
    

    【讨论】:

    • 请询问接受答案的作者,以使用此信息改进他的答案。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-04-09
    • 1970-01-01
    • 1970-01-01
    • 2017-02-26
    • 2017-05-24
    • 2018-04-12
    相关资源
    最近更新 更多