1

I am uploading a video using NSURLSession, right now my video is successfully uploaded. but once wifi connection OFF, the below delegate method is executed right away.

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

How I can resume upload when WIFI connection is back?

Utsav Dusad
  • 2,139
  • 4
  • 31
  • 52
QueueOverFlow
  • 1,336
  • 5
  • 27
  • 48

1 Answers1

0

You can do the upload using Background session. If you use the Default session and the wifi goes down while uploading then completion handler runs right away. Due to which you won't be able to do resume when the network comes back. But if you use the Background session and if the wifi goes down while uploading then the completion handler doesn't run until some timeout (resource timeout) occurs. Whenever the wifi is back it either resumes the upload or start it again, depending on the server.

Upload and download tasks in background sessions are automatically retried by the URL loading system after network errors. It is unnecessary to use reachability APIs to determine when to retry a failed task.

Source: URL Session Programming Guide

Utsav Dusad
  • 2,139
  • 4
  • 31
  • 52