0

I am using universal linking in my project.

I have made apple-app-site-association file in server.

I enable in developer account, Xcode for associate domains and I wrote

applinks:www.laundry.com

The code used in AppDelegate is:-

//Universal links in swift delegatemethod.
    func application(_ application: UIApplication,
                     continue userActivity: NSUserActivity,
                     restorationHandler: @escaping ([Any]?) -> Void) -> Bool
    {
        if userActivity.activityType == NSUserActivityTypeBrowsingWeb {
            let url = userActivity.webpageURL!
            let userurl = url.absoluteString
            // print(url.absoluteString)
            //handle url
            if defaultValues.value(forKey: accessToken) != nil
            {
                print("user url is:",userurl)
                let mainStoryboard: UIStoryboard = UIStoryboard(name: "Pickup", bundle: nil)

                let innerPage: PickupController = mainStoryboard.instantiateViewController(withIdentifier: "PickupController") as! PickupController
                innerPage.selectedfrom = "Deeplink"
                self.window?.rootViewController = innerPage
            }else{
                setRootControllerBeforeLogin()
            }
        }
        return true
    }

But it is not working, please help to me.

iOS Developer
  • 464
  • 6
  • 24
  • What do you mean by "it's not working"? Is the method not getting called? Or the method gets called, but it doesn't do what you expect to? Also, are you testing on simulator or device? – Cristik Jul 02 '19 at 04:51
  • Also, are the app id and app bundle the same in the app site association file and your app? – Cristik Jul 02 '19 at 04:53
  • And not last, check https://stackoverflow.com/questions/32751225/ios9-universal-links-does-not-work, maybe you'll find the answer to your problem there – Cristik Jul 02 '19 at 04:56
  • Actually it don't call that delegate method directly it open to webpage not mobile app. – srikanth stackflow Jul 02 '19 at 05:32
  • I already put check and give the print statement [user url is:] These are also not print. – srikanth stackflow Jul 02 '19 at 05:34

2 Answers2

0

I once used dynamic links of firebase, and override another function in appDelegate like below.

func application(_ application:UIApplication, open url: URL, options: [UIApplication.OpenURLOptionsKey: Any]) -> Bool {
    print("I have received a URL through custom url scheme : \(url.absoluteString)")
    // tot do with dynamic link....
    if let dynamicLink = DynamicLinks.dynamicLinks().dynamicLink(fromCustomSchemeURL: url) {

        return true
    } else {
        // handle others like twitter or facebook login
    }

}
erkutbas
  • 305
  • 2
  • 9
0

Do it on App delegate

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


    if let url = userActivity.webpageURL {
        let component = URLComponents.init(string: url.absoluteString)!
        print(component.path)
    }

        return true



}
Dharman
  • 30,962
  • 25
  • 85
  • 135
VinothV
  • 29
  • 2