Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Get value of parameters in deep link url iOS

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 !!!!

like image 273
Linar sen Avatar asked Jun 16 '17 04:06

Linar sen


1 Answers

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
   }
like image 57
Sour LeangChhean Avatar answered Oct 14 '22 05:10

Sour LeangChhean