gpt4 book ai didi

ios - 如何从 didReceiveRemoteNotification 返回数据中获取数据?

转载 作者:可可西里 更新时间:2023-10-31 23:58:45 25 4
gpt4 key购买 nike

使用 swift3 在​​ xcode8 上运行

下面是我在 AppDelegate.swift 中的代码

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

当我收到通知并单击它时,我的调试区域将如下所示

==== didReceiveRemoteNotification ====
[AnyHashable("type"): order, AnyHashable("aps"): {
alert = "[TestMessage]";
badge = "<null>";
category = alert;
sound = default;
}, AnyHashable("url"): http://www.google.com]

我的问题是如何使用 userInfo 从 AnyHashable("url") 获取数据,即“www.google.com”?

我试试

print(userInfo[AnyHashable("url")])

但是调试区的输出是

Optional(http://www.google.com)

最佳答案

尝试 print(userInfo[AnyHashable("url")] as?String ?? "") 或者您可以将其转换为 URL

关于ios - 如何从 didReceiveRemoteNotification 返回数据中获取数据?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43466917/

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