Get value of parameters in deep link url iOS

▼魔方 西西 提交于 2019-12-03 10:10:27

问题


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.

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

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

Really Thanks for your help !!!!


回答1:


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
   }


来源:https://stackoverflow.com/questions/44580871/get-value-of-parameters-in-deep-link-url-ios

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!