【问题标题】:FCM notification received but data part is not received收到 FCM 通知但未收到数据部分
【发布时间】:2020-07-06 15:18:52
【问题描述】:

我正在使用 firebase 推送通知服务向 ios 设备发送通知。 我们从服务器“数据”和“通知”发送两个通知,但在数据中我们正在发送通知 id,我正在尝试获取通知 id 在 api 中发送该 id 以显示视图通知但在我的情况下,我收到通知,但无法从数据负载中捕获通知 ID。

这是我们从服务器发送的负载。

data = new{                 
 title = pushMessage.Msgtype,                             
 description = pushMessage.Msgdesc,
 image = pushMessage.ImageURL,
 id = pushMessage.NotificationId },

notification = new  {
 body = pushMessage.Description,
 title = pushMessage.Title                            
} 

这是我试图捕获 id 的代码。

func userNotificationCenter(_ center: UNUserNotificationCenter,
                                didReceive response: UNNotificationResponse,
                                withCompletionHandler completionHandler: @escaping () -> Void) {
        let userInfo = response.notification.request.content.userInfo
        
        if let dict = response.notification.request.content.userInfo as? [AnyHashable : Any] {
      
            webServices.notificationId = dict["id"] as? Int
        } 
}

【问题讨论】:

  • 无法从数据负载中捕获通知 ID - 请出示您的代码。
  • 格式应该是-
  • @vpoltave 请检查我用代码更新我的问题。

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


【解决方案1】:

有效载荷应该像 -

{
  aps={
    alert={
      body="Testing ppt 2";
      title="Online Training";
          };
      };
  "data"= {"id":"1"};
}

【讨论】:

    猜你喜欢
    • 2021-10-30
    • 2019-08-17
    • 1970-01-01
    • 1970-01-01
    • 2020-04-25
    • 1970-01-01
    • 1970-01-01
    • 2021-06-25
    • 2018-12-04
    相关资源
    最近更新 更多