sendAsynchronousRequest deprecated in iOS 9, how do I fix my function

nsurlconnection deprecated
nsurlsession objective-c example
nsurlconnection sendasynchronousrequest
nsurlsession synchronous call
nsurlconnection sendsynchronousrequest example
nsurlsession connection pool
urlsession ios
nsurlconnection swift 4 example

An extension on my UIImageView is giving me a warning. I would like a warning free project but I'm not sure how to fix this properly. The warning I receive is this:

sendAsynchronousRequest was depricated in iOS 9.0: Use [NSURLSession dataTAskWithRequest....

The extension that's causing the warning is this:

extension UIImageView {
    public func imageFromUrl(urlString: String) {
        if let url = NSURL(string: urlString) {
            let request = NSURLRequest(URL: url)
            NSURLConnection.sendAsynchronousRequest(request, queue: NSOperationQueue.mainQueue()) {
                (response: NSURLResponse?, data: NSData?, error: NSError?) -> Void in
                if let imageData = data as NSData? {
                    self.image = UIImage(data: imageData)
                }
            }
        }
    }
}

Try this for

Swift 3.0

URLSession.shared.dataTask(with: request) {data, response, error in
   if (error == nil) {
      //Do needful things // Your code . . . 
   } else {
      print("Error : \(error?.localizedDescription)");
   }
}.resume();

sendAsynchronousRequest was deprecated in iOS 9, How to alter , Use NSURLSession instead like below,. For Objective-C NSURLSession *​session = [NSURLSession sharedSession]; [[session dataTaskWithURL:[NSURL​  ios,swift. I think your problem is that you are using a calendar with an unset time zone. Your calculation of adding 60*60*24*2 to the current time does not account for the two days when some timezones change to and from daylight savings time. Those days are 23 and 25 hours long.


Your warning clearly says that sendAsynchronousRequest was depricated in iOS 9.0: Use [NSURLSession dataTAskWithRequest that means you should use NSURLSession instead of NSURLConnection!!!

You should do something like,

 var task = session.dataTaskWithRequest(request, completionHandler: {data, response, error -> Void in
    print("Response: \(response)")})

task.resume()

Swift 2, But the warning is correct, you should avoid using deprecated methods in now-​developing apps, especially when it's a synchronous method. To  Swift 4 / Xcode 9. If you really want the request to be synchronous like in the deprecated semantics, you can block the main thread with an empty loop on a condition set true by the completion handler:


For Swift 4.0 use this:

let request = URLRequest(url: URL(string: "URL Here")!)

let session = URLSession.shared
let task = session.dataTask(with: request, completionHandler: { data, response, error -> Void in

    do {
        //your code here
    } catch {
        print("error")
    }

})

task.resume()

How to do synchronous network calls if NSURLCon |Apple , I noticed that in iOS 9 (Xcode 7.0 beta 7A121l), Apple is depreciating NSURLConnection. is deprecated: first deprecated in iOS 9.0 - Use [​NSURLSession In the above example, I need to make multiple synchronous calls, serially. The correct solution, IMO, is to fix the server and, from there, rewrite  With this update your iPhone, iPad and iPod touch become more intelligent and proactive with powerful search and improved Siri features. New multitasking features for iPad allow you to work with two apps simultaneously, side-by-side or with the new Picture-in-Picture feature. And, built-in apps become more powerful with detailed transit information in Maps, a redesigned Notes app, and an all


JSON parsing in swift different ways. Which one to use?, I saw another tutorial which was using functions like the following to parse JSON- //Making the API Request First, and most importantly, NSURLConnection is deprecated in iOS 9. The sendAsynchronousRequest method is simpler to implement, but not as powerful. (I fixed a couple of typos in Apple's docs in my quote. Making HTTP and HTTPS Requests OS X and iOS provide a number of general-purpose APIs for making HTTP and HTTPS requests. With these APIs, you can download files to disk, make simple HTTP and HTTPS requests, or precisely tune your request to the specific requirements of your server infrastructure.


iOS 9 errors and correct conversion to swift 2, So after updating to iOS 9 and Swift 2 I had many errors in my project that but <​strong>sendAsynchronousRequest was deprecated in iOS  iOS System Recovery can help you easily to fix iPhone, iPad and iPod touch when device stuck in Recovery Mode, Apple logo, and fix iOS 13/12/iOS 11/10.3/9/8/7 system to normal without data loss.


St4k, Authentication with NSURLConnection sendAsynchronousRequest with Do I need to alloc and init the NSURLConnection and set a delegate instead I think I understand how to authenticate correctly with the delegate function but Please note this code gives you a warning now deprecated in iOS 9 . In my case, the problem persisted after removing the ads package. It turned out that one of my plugins was using this outdated function. I did a global code search for `TargetGuidByName` that led me to the culprit line so that I could update it.