3

I'm fighting with NSURLSession upload & download, everything seems to work if not for the fact that, for example, at in the background of 100 files sent (upload) the :

- (void)URLSession:(NSURLSession *)session task:(NSURLSessionTask *)task didCompleteWithError:(NSError *)error

not always invoked by the system, regardless of the file sent correctly.

More is almost always invoked at the end of the session ...

It is normal behavior or am I making mistakes ... ??

I also did some testing using AFNetworking but I always get the same behavior.

thanks !

  • Have the same problem. – Avt Sep 24 '15 at 19:12
  • Did you try to invalidate the session before create a new one? this that answer: http://stackoverflow.com/questions/31262564/nsurlsession-didcompletewitherrorgets-called-with-nserror-is-nil/37240344#37240344 – christian mini May 15 '16 at 17:05

1 Answers1

1

In my case delegate method func urlSession(_ session: URLSession, task: URLSessionTask, didCompleteWithError error: Error?) was not called in Swift 3.0 because it still depends on Objective-C. So please use next code for delegate method:

@objc(URLSession:task:didCompleteWithError:)
func urlSession(_ session: URLSession, task: URLSessionTask, didCompleteWithError error: Error?) {
  //your code here
}
FelixSFD
  • 6,052
  • 10
  • 43
  • 117
razor28
  • 1,077
  • 10
  • 17