Wassim Seifeddine
Wassim Seifeddine

Reputation: 1022

iOS Deep Link doesn't call any function from the AppDelegate

I'm having an issue with Deep Linking. when I go to safari, In the url i enter myapp:// and press Enter. it redirects me to the app.

However none of the function in the AppDelegate is getting called.

I need to take the parameters from the URL.

 func application(_ application: UIApplication, continue userActivity: NSUserActivity, restorationHandler: @escaping ([Any]?) -> Void) -> Bool {
    print("Continue User Activity: ")

    return true
}
 func application(_ application: UIApplication, handleOpen url: URL) -> Bool {
    showSimpleAlertView("hahah", message: "adasdasds", withPresneter: self.window!.rootViewController!, withCompletionHandler: nil)
    return true 
}

As from the online tutorial, on of these 2 function should get called.

Upvotes: 3

Views: 5407

Answers (2)

Julian B.
Julian B.

Reputation: 3725

I ran into the same issue today. After doing some research I learned there's a new method in iOS 13 that captures the deep linking URs. Within SceneDelegate try this:

    func scene(_ scene: UIScene, openURLContexts URLContexts: Set<UIOpenURLContext>) {

        if let deepLinkContext = URLContexts.first {
            print("the url \(deepLinkContext.url)")
            print("the options \(deepLinkContext.options)")
        }
    }
    

Upvotes: 3

jjv360
jjv360

Reputation: 4140

I believe that handleOpen function was deprecated in iOS 9... Try this one instead:

func application(_ application: UIApplication, open url: URL, options: [UIApplicationOpenURLOptionsKey : Any] = [:]) -> Bool {

Upvotes: 1

Related Questions