I am using UIBackgroundtaskIdentifier to create background task of uploading images to server.
NSLog(@"Time left = %.1f seconds", [UIApplication sharedApplication].backgroundTimeRemaining);
When I take the application in to background, it show that applicaiton have 179 seconds to run in background. I log the server responses as it uploads that images one by one.
[[DataCoordinator sharedInstance] setBackgroundTask:[[UIApplication sharedApplication] beginBackgroundTaskWithExpirationHandler:^{
NSLog(@"No background task should run now.");
[[UIApplication sharedApplication] endBackgroundTask:[[DataCoordinator sharedInstance] backgroundTask]];
[[DataCoordinator sharedInstance] setBackgroundTask:UIBackgroundTaskInvalid];
}]];
The strange thing happening here is that, after the time provided by iOS for my application to run in background is over still the upload doesn't stops. Suppose I tried uploading 33 images, and when 179 seconds got complete application was successful uploading only 9 out of 33 images. But the process doesn't stop. And application keep uploading the remaining pictures.