ios - NSURLSessionTask. Suspend does not work -


this apple's documentation says regarding suspend method of nsurlsessiontask class

a task, while suspended, produces no network traffic , not subject timeouts.

ok. i'm running 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 wrapper around dispatch_after , request http://httpbin.org/delay/10 gives response after 10 seconds. in middle of waiting response suspend task. not work. in 60 seconds completion block called timeout error. can please explain what's wrong?

this appears normal behaviour, more definitive documentation apple useful in clarifying seeing.

apple’s documentation not provide detailed explanation of how suspend works, or when should used. however, my view (based on testing , research) suspend() should used download tasks. data tasks should use resume() (to start task) , cancel() when appropriate.

my testing, using xcode , charles proxy, revealed suspended data task has no effect on network traffic indicated in apple’s documentation. in other words, network traffic produced.

i observed 2 things using suspend , data tasks:

1) if it's called right after resume, has no effect on data task. not suspend network traffic , barring no network or server side-side issues, successful response received in callback.

2) if it's called in dispatch.asyncafter callback, still not suspend network traffic, callback gets “request timeout” error instead of successful response. according charles proxy, request successful though. result leads me believe suspend() should not be used data tasks. result of callback useless in opinion.

cancelling data task:

cancel() works expected. client (you) closes connection before getting complete response server. can done right after calling resume() or @ later time (before request has completed of course).


Comments

Popular posts from this blog

account - Script error login visual studio DefaultLogin_PCore.js -

xcode - CocoaPod Storyboard error: -