简体   繁体   中英

SWIFT :- Universal linking in swift is not working

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.

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
    }

}

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



}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM