NSURLSessionResponseCancel produces error?

199 views Asked by At

I used NSURLConnectionobject and called its method cancel sometimes.

Now I should replace NSURLConnection -> NSURLSession. NSURLSession operates with tasks which have cancel method too.

The problem is -[NSURLConnection cancel] just stop the handling of requests but if I use -[NSURLSessionTask cancel] it produces "cancelling error". So how to properly distinguish if cancel is called manually or if a real error is occurred?

2

There are 2 answers

0
Vyachaslav Gerchicov On

I've found 3 solutions:

  • subclass task/session class

  • create a custom property via method swizzling in task/session class

  • the simplest but not very beautiful way - task has string property taskDescription and documentation says that developers are free to use it as they want.

2
dgatwood On

Compare the error code to NSURLErrorCancelled. This error code is generated only when your code cancels the request.