我正在尝试使用以下代码将通知打印为字符串:
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
我在做什么错了?
答案 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!)
}