I'm currently working on support for this, but I can't seem to figure out how to test it.
It seems to work fine with my application in the background, and although I can't seem to automate a test for this, I can acceptance test it.
However, if my app is quit, then I don't seem to get a call to application:handleEventsForBackgroundURLSession:completionHandler: within a relaunched instance of my app nor is the file I've requested to download actually downloaded. I'm quitting my app via exit(EXIT_SUCCESS), which I suspect isn't ideal, but there doesn't seem to be another mechanism for killing it. I have tried to manually swipe the application up to remove it from the list of running apps on double tapping home, but this doesn't work either.
Do you have any suggestions on how I might be able to test this?
Some snippets of my code:
NSURL *url = "">NSURLRequest *request =
[NSURLRequest requestWithURL:url
cachePolicy:NSURLRequestReloadIgnoringCacheData
timeoutInterval:60];
NSString *identifier =
[NSString stringWithFormat:@"SessionId_%@", [[NSUUID UUID] UUIDString]];
NSURLSessionConfiguration *config =
[NSURLSessionConfiguration backgroundSessionConfiguration:identifier];
NSURLSession *session =
[NSURLSession sessionWithConfiguration:config
delegate:self
delegateQueue:[NSOperationQueue mainQueue]];
NSURLSessionTask *sessionTask = [session downloadTaskWithRequest:request];