【发布时间】: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