Search code examples
nsurlconnection

NSURLConnection was deprecated in iOS 9, How to fix it


I am getting the issue with: enter image description here

Can someone help me How to fix this warning?


Solution

  • NSURLConnection is deprecated in iOS9 just use NSURLSession instead.

    In your case it will look approximately as follows:

    let url = NSURL(string: urlString as String))
    var task: NSURLSessionDataTask!
    let configuration = NSURLSessionConfiguration.defaultSessionConfiguration()
    let session = NSURLSession(configuration: configuration)
    let request = NSMutableURLRequest(URL: url)
    
    task = session.dataTaskWithRequest(request, completionHandler: { (data, response, error) -> Void in
        // Your code
    })
    
    task.resume()