2

What happens to an ephemeral NSURLSession of type data task when an app switches from the foreground or iOS looses network connectivity?

In particular, will its NSURLSessionDelegate be notified, or do I have to observe at the level of UIApplicationWillResignActiveNotification (as well as UIApplicationWillTerminateNotification) and kReachabilityChangedNotification respectively, if I don't want the NSURLSession to disappear "silently".

Community
  • 1
  • 1
Drux
  • 11,992
  • 13
  • 66
  • 116
  • The task will end up with an error when appropriate, isn't that enough for you? – jcaron Aug 29 '16 at 08:35
  • @jcaron So are you saying that the delegate's `URLSession:task:didCompleteWithError:` will always be called with `error != nil` when one of the two scenarios occurs? – Drux Aug 29 '16 at 08:44
  • I'm not certain just going to background will necessarily abort the transfer (I wouldn't be surprised if it kept on running for at least a few seconds, so that you can come back to the app and continue as if nothing happened – this is especially true for resigning active rather than actually going to background), though I haven't tested it. Likewise, depending on the exact "connectivity loss" scenario (actually losing the network/packet loss), the transfer may try to continue as well. But I'm quite confident that if the transfer is finally aborted, you'll get the error reported. Just test it! – jcaron Aug 29 '16 at 08:51

0 Answers0