迅速-通知标题到字符串

时间:2018-06-27 10:31:39

标签: swift string xcode push-notification

我正在尝试使用以下代码将通知打印为字符串:

func application(_ application: UIApplication,
                 didReceiveRemoteNotification userInfo: [AnyHashable : Any],
                 fetchCompletionHandler completionHandler: @escaping (UIBackgroundFetchResult) -> Void) {

    let dict = userInfo["aps"] as! NSDictionary
    let title = dict["alert"]
    let message = dict["message"] as? NSString
    print ("@", title!)
    print ("@", message)
}

打印:

@ {
    title = "Germany won";
}
@ nil

我在做什么错了?

1 个答案:

答案 0 :(得分:0)

问题已解决:

    func application(_ application: UIApplication,
                 didReceiveRemoteNotification userInfo: [AnyHashable : Any],
                 fetchCompletionHandler completionHandler: @escaping (UIBackgroundFetchResult) -> Void) {

    let dict = userInfo["aps"] as! NSDictionary
    let title = dict["alert"] as! NSDictionary
    let message = title["title"]
    print ("@", title)
    print ("@", message!)
}