The URLSession:task:didCompleteWithError:
method of NSURLSessionTaskDelegate
should be called when your upload is done. Refer to the task.response
object, which should be the NSHTTPURLResponse
object.
I'm sure you're doing this, but the standard background upload task components are:
Make a background session:
NSURLSessionConfiguration *backgroundConfiguration = [NSURLSessionConfiguration backgroundSessionConfiguration:@"com.domain.app"]; NSURLSession *session = [NSURLSession sessionWithConfiguration:backgroundConfiguration delegate:self delegateQueue:[NSOperationQueue mainQueue]];
Use the
NSURLSession
methoduploadTaskWithRequest:fromFile:
method:NSURLSessionTask *task = [session uploadTaskWithRequest:request fromFile:fileURL]; [task resume];
With a background session, you must:
Use
NSURLSessionUploadTask
;Use file-based rendition (you cannot use
NSData
based version);Use delegate-based rendition cannot use data tasks; (b)
NSData
rendition of theNSURLSessionUploadTask
; nor (c) a completion block rendition of theNSURLSessionUploadTask
.
With upload tasks, make sure to not call
setHTTPBody
of aNSMutableRequest
. With upload tasks, the body of the request cannot be in the request itself.Make sure you implement the appropriate
NSURLSessionDelegate
,NSURLSessionTaskDelegate
methods.Make sure to implement
application:handleEventsForBackgroundURLSession:
in your app delegate (so you can capture thecompletionHandler
, which you'll call inURLSessionDidFinishEventsForBackgroundURLSession
).