2

I built an app, more than an year ago, that provides photo sharing and video sharing for its users. It ran without any problems until a couple of weeks ago where I introduced a new feature: the possibility of marking a video to be uploaded only when WiFi is available: the video is set to use an NSURLSession with a NSURLSessionConfiguration where allowsCellular is set to NO.

Most of the time it works fine:

  • I set a video to be share on WiFi while I'm connected through 3G/4G
  • Once I connect to a WiFi network the video is uploaded without issues

However, some users, don't have their videos uploaded once they connect to WiFi. I got some logs from them and I can see an error whenever they connect to Wifi, for some reason NSURLSession makes the delegate call to:

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

With the following error:

Error: Error Domain=NSURLErrorDomain Code=-999 "(null)" UserInfo={NSErrorFailingURLStringKey=https://my-videos-bucket.s3.amazonaws.com/4074196678138134606/F17F7308-2810-4325-A5AF-BB8FFC093AC6.mov, NSURLErrorBackgroundTaskCancelledReasonKey=0, NSErrorFailingURLKey=https://my-videos-bucket.s3.amazonaws.com/4074196678138134606/F17F7308-2810-4325-A5AF-BB8FFC093AC6.mov}

Any ideas? Could it be a problem with the server? The odd thing is that I can't reproduce it nor understand the reason for failure

Thanks in advance!

Ze

user361526
  • 2,843
  • 5
  • 23
  • 33

1 Answers1

1

A 999 error normally occurs when your app cancels the request—either by explicitly canceling the task itself or by invalidating (or possibly releasing) the session that contains it.

However, in the case of background downloads, the framework provides a little more info. You'll notice the dictionary key NSURLErrorBackgroundTaskCancelledReasonKey) has a value of 0. If you look that up in the documentation, you'll find that this corresponds with NSURLErrorCancelledReasonUserForceQuitApplication.

In other words, the request was cancelled because the user explicitly double-tapped the home button and swiped upwards to terminate your app. The background download was automatically canceled as a result.

See NSURLSession Class Reference for more info.

dgatwood
  • 9,519
  • 1
  • 24
  • 48