Using multiple beginBackgroundTaskWithExpirationHandler calls
<p>I am trying to follow this previous post here: <a href="http://stackoverflow.com/questions/3928861/best-practice-to-send-a-lot-of-data-in-background-on-ios4-device">Best practice to send a lot of data in background on iOS4 device?</a></p>

<p>And basically, I have a method called getRequest that grabs information from the web server.  There are about 50 pieces of data I need from the web server.  So at the same time, I have 50 delegate calls to connectionDidFinishLoading.  Currently my getRequest looks like:</p>

<pre><code>-(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");
    }

}
</code></pre>

<p>Then in my connectionDidFinishLoading:</p>

<pre><code>- (void)connectionDidFinishLoading:(NSURLConnection *)connection {
        // process data from server
   // endBackgroundTask:someTaskID???
}
</code></pre>

<p>I know you are allowed to have multiple calls of beginBackgroundTaskWithExpirationHandler, but I don't know if what I'm doing in my getRequest method is doing that since I only have one variable <code>__block UIBackgroundTaskIdentifier taskID</code> each time the method is called.  And I'm also not sure if I need to call endBackgroundTask in the connectionDidFinishLoading method for each call to getRequest since you are supposed to balance the beginBackgroundTaskWithExpirationHandler with an endBackgroundTask: call.  If so, how do I do that since my getRequest doesn't currently have that infrastructure?  Do I need 50 ivars in order for the connectionDidFinishLoading method to see the 50 initial calls to getRequest? Thanks.</p>
