I try to follow this previous post here: Best practice sending large amounts of data in the background on an iOS4 device?
And basically, I have a method called getRequest that grabs information from a web server. The web server requires about 50 data units. Therefore, at the same time, I have 50 delegate calls to connectionDidFinishLoading. Currently my getRequest looks like this:
-(void) getRequestWithURL:(NSString *) requestURL
{
static int getRequest = 0;
NSLog(@"getRequest: %i", getRequest);
getRequest++;
UIApplication *app = [UIApplication sharedApplication];
__block UIBackgroundTaskIdentifier taskID;
taskID = [app beginBackgroundTaskWithExpirationHandler:^{
NSLog(@"Time remaining: %f", app.backgroundTimeRemaining);
NSLog(@"Background task not completed");
[app endBackgroundTask:taskID];
}];
NSURLRequest *req = [[NSURLRequest alloc] initWithURL:[NSURL URLWithString:requestURL]];
NSURLConnection *con = [[NSURLConnection alloc] initWithRequest:req delegate:self] ;
[self startRequestWithConnection:con];
[req release];
if (taskID == UIBackgroundTaskInvalid) {
NSLog(@"Failed to create background task identifier");
}
}
Then in my connection DidFinishLoading:
- (void)connectionDidFinishLoading:(NSURLConnection *)connection {
}
, beginBackgroundTaskWithExpirationHandler, , , getRequest, __block UIBackgroundTaskIdentifier taskID . , endBackgroundTask connectionDidFinishLoading getRequest, startBackgroundTaskWithExpirationHandler endBackgroundTask:. , , getRequest ? 50 ivars connectionDidFinishLoading, 50 getRequest? .