Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/swift/16.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何使用swift 3将通知详细信息检索到单个数据元素中_Swift_Push Notification - Fatal编程技术网

如何使用swift 3将通知详细信息检索到单个数据元素中

如何使用swift 3将通知详细信息检索到单个数据元素中,swift,push-notification,Swift,Push Notification,我正在尝试读取某个应用程序收到的所有通知,并将其加载到集合视图中。希望能够检索标题、正文。。。个别地。我的计数返回正常,但content.body和content.title为空。无法返回notification.description,但为完整字符串。我必须手动解析描述吗 谢谢你的帮助 //read all existing notifications func listNotification() { UNUserNotificationCenter.current().getDe

我正在尝试读取某个应用程序收到的所有通知,并将其加载到集合视图中。希望能够检索标题、正文。。。个别地。我的计数返回正常,但content.body和content.title为空。无法返回notification.description,但为完整字符串。我必须手动解析描述吗

谢谢你的帮助

//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附件:[未通知附件]