在深层链接URL iOS中获取参数的值 [英] Get value of parameters in deep link url iOS

查看:371
本文介绍了在深层链接URL iOS中获取参数的值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

每个人. 我的问题是:如何从深层链接URL获取数据? 我有两个应用程序,我想使用深层链接将数据从app1发送到app2. 我在app1上有一个按钮,可以单击并打开app2,然后app 2将通过深链接URL从app1中获取数据.

everyone. My question is: How can I get data from deep link URL? I have two apps and I want to send data from app1 to app2 using the deep link. I have a button on app1 to click and open app2 then app 2 will get data from app1 by deep link URL.

这是我在app1中发送按钮的代码:

Here is my code of button send in app1:

@IBAction func btnSend_Clicked(_ sender: Any) {
    let text = self.txtInput.text?.replacingOccurrences(of: " ", with: "%20")
    UIApplication.shared.open(URL(string: "myapp://?code=\(text!)")!, options: [:], completionHandler: nil)
}

那么,如何从app2中的Deeplink网址(代码参数)获取数据?

so, How can i get data from deeplink url (code parameter) in app2?

真的谢谢您的帮助!!!!

Really Thanks for your help !!!!

推荐答案

您可以在Appdelegate中实现以下代码:

You implement this code in Appdelegate:

 func application(_ app: UIApplication, open url: URL, options: [UIApplicationOpenURLOptionsKey : Any] = [:]) -> Bool {
        let urlComponents = URLComponents(url: url, resolvingAgainstBaseURL: false)
        let items = (urlComponents?.queryItems)! as [NSURLQueryItem]
        if (url.scheme == "myapp") {
            var vcTitle = ""
            if let _ = items.first, let propertyName = items.first?.name, let propertyValue = items.first?.value {
                vcTitle = url.query!//"propertyName"
               }
        }
        return false
   }

这篇关于在深层链接URL iOS中获取参数的值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆