0

I'm Receiving Response from api using post method like this

'Success{
shortlink = pAHJt7;
status = 200;
} '

I want to use only shortlink with my url to share using deep linking concept.
Here is my code of post method in which I'm getting response from api

    func postRequest(latitude:Double,longitude:Double) {
        guard let url = URL(string: "http://i.Mallangtech.com/api/Url") else{
            
            return
        }
        var request = URLRequest(url: url)
        request.httpMethod = "POST"
        request.setValue("application/Json", forHTTPHeaderField: "Content-Type")
        let body:[String: AnyHashable] = [
            "status": 200,
            "shortlink":"okko"]
        request.httpBody = try? JSONSerialization.data(withJSONObject: body, options: .fragmentsAllowed)
        
        //hiting api
        
        let task = URLSession.shared.dataTask(with: request) { data, _, Error in
            guard let data = data, Error == nil else {
                return
            }

                do{
            
                let response = try JSONSerialization.jsonObject(with: data, options: .allowFragments)
            print("Success\(response)")
                
            }
            catch{
                print (error)
            }
            }
        task.resume()
  
    }

  

     ```

1 Answers1

0

Lets divide this feature into 4 steps.

  1. Getting Response from API
  2. Sharing the deep link to user.
  3. If user clicks, open the screen
  4. Load the screen with given url.

You have already done the step 1.

For step 2, You can use UIActivityViewController. You can refer this for its implementation.

For step 3 and 4, You need to configure for deep link and handle it inside SceneDelegate. Refer this and you can launch a view controller from SceneDelegate with required params.

Mayank
  • 614
  • 1
  • 5
  • 11