Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 
avatar of Priyank Gujarati

Priyank Gujarati

Priyank Gujarati has asked 0 questions and find answers to 1 problems.

Stats

15
EtPoint
3
Vote count
0
questions
1
answers

About

ios Developer

Ahmedabad

http://www.webmd.com/men/ss/slideshow-flat-abs-for-men

let data = try JSONSerialization.data(withJSONObject: dictJson, options: .prettyPrinted) var request = URLRequest(url: url, cachePolicy: .reloadIgnoringLocalAndRemoteCacheData, timeoutInterval: AppDelegate.shared.timeoutInterval)

        request.httpMethod = "POST"
        request.setValue("application/json", forHTTPHeaderField: "Content-Type")
        request.httpBody = data

        var strMessage = ""

        let dataTask = session.dataTask(with: request, completionHandler: {
            data , response , error in

            if error == nil && data != nil{
                if let httpResponse = response as? HTTPURLResponse{
                    if httpResponse.statusCode == 200{
                        self.postCarParseResponseData(data!)
                    }else{
                        do{
                            let responseData = try JSONSerialization.jsonObject(with: data!, options: .mutableContainers)
                            if let response = responseData as? [String:Any]{
                                if let message = response["message"] as? String{
                                    strMessage = message
                                }
                                DispatchQueue.main.async {
                                    self.delegate.carListParserFailure(strMessage)
                                }
                            }
                        }catch{
                            DispatchQueue.main.async {
                                self.delegate.carListParserFailure("\(error.localizedDescription)")
                            }
                        }
                    }
                }
            }else{
                DispatchQueue.main.async {
                    self.delegate.carListParserFailure(error!.localizedDescription)
                }
            }
        })
        dataTask.resume()

    }catch{
        self.delegate.carListParserFailure("")
    }
}

++++++++++++ do{ let responseData = try JSONSerialization.jsonObject(with: data, options: .mutableContainers)

        if let response = responseData as? [String:Any]{

}catch{ DispatchQueue.main.async { self.delegate.carListParserFailure("(error.localizedDescription)") } }

Priyank Gujarati questions

Priyank Gujarati answers