如何使用swift 3将通知详细信息检索到单个数据元素中
我正在尝试读取某个应用程序收到的所有通知,并将其加载到集合视图中。希望能够检索标题、正文。。。个别地。我的计数返回正常,但content.body和content.title为空。无法返回notification.description,但为完整字符串。我必须手动解析描述吗 谢谢你的帮助如何使用swift 3将通知详细信息检索到单个数据元素中,swift,push-notification,Swift,Push Notification,我正在尝试读取某个应用程序收到的所有通知,并将其加载到集合视图中。希望能够检索标题、正文。。。个别地。我的计数返回正常,但content.body和content.title为空。无法返回notification.description,但为完整字符串。我必须手动解析描述吗 谢谢你的帮助 //read all existing notifications func listNotification() { UNUserNotificationCenter.current().getDe
//read all existing notifications
func listNotification() {
UNUserNotificationCenter.current().getDeliveredNotifications(
completionHandler: {receivedNotifications -> () in
print("Received notification #\(receivedNotifications.count)")
for notification in receivedNotifications {
let content = UNMutableNotificationContent()
print(" Body \(content.body)")
print(" Title \(content.title)")
}
}
}
您正在打印常量
content
的内容,但是您没有使用正在迭代的通知对其进行初始化,代码中没有读取此变量的地方
for notification in receivedNotifications {
let content = notification.request.content
print(" Body \(content.body)")
print(" Title \(content.title)")
}
这样试试看
getDeliveredNotifications
返回一个数组,其中每个数组都有一个请求(),并且在以下实例中:
变量标题:字符串
字幕:字符串
变量主体:字符串
var徽章:NSNumber
var声音:无提示声音
var launchImageName:字符串
var userInfo:[AnyHashable:Any]
var附件:[未通知附件]