【问题标题】:SWIFT :- Universal linking in swift is not workingSWIFT :- swift 中的通用链接不起作用
【发布时间】:2019-07-02 04:45:21
【问题描述】:

我在我的项目中使用通用链接。

我已经在服务器中创建了 apple-app-site-association 文件。

我在开发者帐户中启用了关联域的 Xcode 和我写的

应用链接:www.laundry.com

AppDelegate中使用的代码是:-

//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
    }

但它不起作用,请帮助我。

【问题讨论】:

  • “它不工作”是什么意思?该方法没有被调用吗?或者该方法被调用,但它没有达到您的预期?另外,您是在模拟器还是设备上进行测试?
  • 另外,应用站点关联文件和您的应用中的应用 ID 和应用包是否相同?
  • 不是最后一个,检查stackoverflow.com/questions/32751225/…,也许你会在那里找到问题的答案
  • 实际上它不会直接调用该委托方法,而是打开网页而不是移动应用程序。
  • 我已经勾选并给出了打印语句[user url is:] 这些也不是打印的。

标签: ios swift ios-universal-links


【解决方案1】:

我曾经使用过firebase的动态链接,并覆盖了appDelegate中的另一个函数,如下所示。

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
    }

}

【讨论】:

  • 我们不使用任何 Firebase。
【解决方案2】:

在应用委托上执行

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



}

【讨论】:

    猜你喜欢
    • 2018-03-16
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-08-26
    • 2014-08-27
    相关资源
    最近更新 更多