swift - 在 getDeliveredNotifications(completionHandler :) method) 中读取推送通知负载详细信息

标签 swift notifications apple-push-notifications ios10

这是我的推送通知负载。

{
    "userId":"QA-207-222820",
    "title":"Push new Notification",
    "message":"New Notification",
    "deviceId":"70",
    "deviceName":"R70",
    "notificationType":"1"
}

无法读取 ios10 中 getDeliveredNotifications 方法内的通知对象中的上述有效负载键和值。

这是 getDeliveredNotifications 方法中通知对象的详细信息。

<UNNotification: 0x1742389a0; date: 2017-12-13 09:34:59 +0000,

 request: <UNNotificationRequest: 0x1742389c0; identifier: 067437A1-E8F3-4805-B6D9-
A57BE48E9554, 

content: <UNNotificationContent: 0x17410ba30; title: (null), 
subtitle: (null), body: New Notification 
, categoryIdentifier: , launchImageName: , peopleIdentifiers: (
), threadIdentifier: , attachments: (
), badge: (null), 

sound: <UNNotificationSound: 0x1740b75e0>, 
hasDefaultAction: YES, defaultActionTitle: (null), shouldAddToNotificationsList: YES,
shouldAlwaysAlertWhileAppIsForeground: NO, shouldLockDevice: NO, shouldPauseMedia: NO, 
isSnoozeable: NO, fromSnooze: NO, darwinNotificationName: (null), darwinSnoozedNotificationName: (null), 

trigger: <UNPushNotificationTrigger: 0x17400e2a0; contentAvailable: YES, mutableContent: NO>>>

除了我的通知消息“New Notification”之外,没有关于我在推送通知中发送的有效载荷的信息,它存在于通知对象的正文键中,有没有办法读取通知对象中的所有有效载荷键。任何帮助将不胜感激。

最佳答案

您的负载应该在通知内容的 userInfo 字典中:

let userInfo = notification.request.content.userInfo
print userInfo["userId"]

关于swift - 在 getDeliveredNotifications(completionHandler :) method) 中读取推送通知负载详细信息,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47790345/

相关文章:

ios - iOS App在后台或未运行时如何响应iOS APNS事件

ios - 当 APNS token 失效时,是否必须重复剩余的推送通知?

ios - 日期(timeIntervalSince1970 :) returns 2 different results

swift - 如何更改一个表格 View 单元格的分隔符颜色?

ios - swift:更改 UIView 的大小

ios - 如何等待给定时间来运行操作 - SWIFT

java - 开源 Java EE 通知框架

Android 在 3 小时后设置通知

c++ - 如何应用CORBA Notification Service?

ssl - 从 coldfusion 发送推送通知?