This is what Apple's documentation says regarding suspend
method of NSURLSessionTask
class
A task, while suspended, produces no network traffic and is not subject to timeouts.
Ok. So I'm running the following simple code:
let url = NSURL(string: "http://httpbin.org/delay/10")!
let urlRequest = NSURLRequest(URL: url)
self.task = NSURLSession.sharedSession().dataTaskWithURL(urlRequest.URL!, completionHandler: {
data, response, error in print("completion ERROR \(error)")
})
self.task.resume()
print("Start")
delay(5, closure: {
self.task.suspend()
print("Suspend")
})
Function delay
is simply a wrapper around dispatch_after
and a request to http://httpbin.org/delay/10
gives response after 10 seconds. In the middle of waiting for response I suspend the task. However that does not work. In 60 seconds the completion block is called with timeout error. Can anybody please explain what's wrong?
dispatch_after
? – Corposant