Running on xcode8 with swift3
Below is my code from AppDelegate.swift
func application(_ application: UIApplication, didReceiveRemoteNotification userInfo: [AnyHashable : Any], fetchCompletionHandler completionHandler: @escaping (UIBackgroundFetchResult) -> Void) {
print("==== didReceiveRemoteNotification ====")
print(userInfo)
}
When I get a notification and click on it, my debug area will how like below
==== didReceiveRemoteNotification ====
[AnyHashable("type"): order, AnyHashable("aps"): {
alert = "[TestMessage]";
badge = "<null>";
category = alert;
sound = default;
}, AnyHashable("url"): http://www.google.com]
My question is how can I use userInfo to get data from AnyHashable("url") which is "www.google.com" ?
I try
print(userInfo[AnyHashable("url")])
but output in debug area is
Optional(http://www.google.com)
Try print(userInfo[AnyHashable("url")] as? String ?? "")
Or you can cast it as URL
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With