I have been using NSURLSession
to do background uploading to AWS S3. Something like this:
NSURLSessionConfiguration* configuration = [NSURLSessionConfiguration backgroundSessionConfigurationWithIdentifier:@“some.identifier"];
NSURLSession* session = [NSURLSession sessionWithConfiguration:configuration delegate:someDelegate delegateQueue:[NSOperationQueue mainQueue]];
NSURLSessionUploadTask* task = [session uploadTaskWithRequest:request fromFile:[NSURL fileURLWithPath:httpBody]];
[task resume];
In someDelegate
, I have implemented didSendBodyData
, didCompleteWithError
and handleEventsForBackgroundURLSession
.
I have three questions:
- I have noticed that if I close the app while uploading is in progress, transfer will continue and successfully finish. Is
handleEventsForBackgroundURLSession
called when the transfer is finished while the app is closed? - Assuming that the answer to the first question is yes, how can I delete
httpBody
inhandleEventsForBackgroundURLSession
? This is a temporary file that is not needed once transfer is complete. - I would appreciate it if someone explained, in detail, how background transfer works in iOS. That is when memory is created, which callbacks are called at which states and how the app is woken up once the transfer is completed. Thanks.