I am trying to run a background NSURLSessionDownloadTask. However, I noticed that it takes approximately 30 seconds before the task actually begins. When I use the defaultSessionConfiguration, the task starts almost immediately. Is there a way to trigger the NSURLSessionDownloadTask immediately when using the backgroundSessionConfiguration?
Below is the result I get when I use backgroundSessionConfiguration:
NSURLSessionConfiguration *sessionConfiguration = [NSURLSessionConfiguration backgroundSessionConfiguration:[NSString stringWithFormat:bgIdentifier, self.urlModel.code]];
Here are the log output. Note that “Start uploading…” is logged right before calling the “resume” method and “Upload progress” is logged in the NSURLSessionTaskDelegate’s didSendData method.
2014-02-18 20:13:55.403 myapp[396:60b] [DoneViewController] Start uploading...
2014-02-18 20:14:17.699 myapp[396:60b] [DoneViewController] Upload progress - 1%
2014-02-18 20:14:17.704 myapp[396:60b] [DoneViewController] Upload progress - 2%
2014-02-18 20:14:17.705 myapp[396:60b] [DoneViewController] Upload progress - 3%
2014-02-18 20:14:17.706 myapp[396:60b] [DoneViewController] Upload progress - 4%
Just for reference, the same thing but with the default session configuration.
NSURLSessionConfiguration *sessionConfiguration = [NSURLSessionConfiguration defaultSessionConfiguration];
You can see there is no delay on console result is like this:
2014-02-18 19:57:00.552 myapp[376:60b] [DoneViewController] Start uploading...
2014-02-18 19:57:00.707 myapp[376:60b] [DoneViewController] Upload progress - 2%
2014-02-18 19:57:00.710 myapp[376:60b] [DoneViewController] Upload progress - 5%
2014-02-18 19:57:00.711 myapp[376:60b] [DoneViewController] Upload progress - 8%
2014-02-18 19:57:00.711 myapp[376:60b] [DoneViewController] Upload progress - 11%
Edit: With iOS 7.1, there are times when there are no delays. However, there are still times where there are about 20 second delays.