Reputation: 1039
I am using the function NSURLConnection sendAsynchronousRequest completionHandler
to send async requests using NSURLConnection.
When this fails, how do I retry the same request? What are the best practices around this?
Upvotes: 0
Views: 171
Reputation: 352
When you call the
sendAsynchronousRequest
you can and should pass a completion handler block to the function. When the request is finished the completion handler gets called with a NSURLResponse,NSData and an NSError object. Just check if the error is nil and you know that your request finished successfully.
Take a look at the documentation:
https://developer.apple.com/library/ios/documentation/Cocoa/Reference/Foundation/Classes/NSURLConnection_Class/index.html#//apple_ref/occ/clm/NSURLConnection/sendAsynchronousRequest:queue:completionHandler:
However if you are developing for iOS9 you should use NSURLSession to make asynchronous network requests because the method in NSURLConnection is deprecated in iOS9 . Here the link to the class reference of NSURLSession: https://developer.apple.com/library/prerelease/ios/documentation/Foundation/Reference/NSURLSession_class/
Upvotes: 2