Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to get data from didReceiveRemoteNotification return data?

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)
like image 575
Dreams Avatar asked Sep 12 '25 19:09

Dreams


1 Answers

Try print(userInfo[AnyHashable("url")] as? String ?? "") Or you can cast it as URL

like image 148
Dharmesh Kheni Avatar answered Sep 14 '25 09:09

Dharmesh Kheni