gpt4 book ai didi

swift - 通知标题到字符串

转载 作者:行者123 更新时间:2023-11-30 11:23:15 25 4
gpt4 key购买 nike

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

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

我做错了什么?

最佳答案

问题已解决:

    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!)
}

关于swift - 通知标题到字符串,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51060537/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com