Note that there are some explanatory texts on larger screens.

plurals
  1. POiOS 4.0 Task Completion in Background
    primarykey
    data
    text
    <p>Using iOS 4.0 I am trying to do a download an image in the background when the app is suspended. What I am doing is when I get the <code>applicationDidEnterBackground</code> delegate call, I initiate one asynchronous <code>NSURLConnection</code> and set the app delegate as the delegate for the connection. But none of the <code>NSURLConnection</code> delegates are getting called back. I have captured the network calls using Wireshark and I can see that my request succeeded and got the response too. But since none of the delegate methods are invoked I am unable to do anything with the data.</p> <pre><code>- (void)applicationDidEnterBackground:(UIApplication *)application { NSLog(@"Application entered background state."); // UIBackgroundTaskIdentifier bgTask is instance variable NSAssert(self-&gt;bgTask == UIBackgroundTaskInvalid, nil); bgTask = [application beginBackgroundTaskWithExpirationHandler: ^{ dispatch_async(dispatch_get_main_queue(), ^{ [application endBackgroundTask:self-&gt;bgTask]; self-&gt;bgTask = UIBackgroundTaskInvalid; }); }]; NSURLRequest *request = [[NSURLRequest alloc] initWithURL:[NSURL URLWithString:@"http://animal.discovery.com/mammals/leopard/pictures/leopard-picture.jpg"] cachePolicy:NSURLRequestReloadIgnoringLocalCacheData timeoutInterval:15]; self.connection = [[[NSURLConnection alloc] initWithRequest:request delegate:self startImmediately:NO] autorelease]; [self.connection scheduleInRunLoop:[NSRunLoop currentRunLoop] forMode:NSRunLoopCommonModes]; [self.connection start]; [request release]; NSLog(@"Sent download request...."); dispatch_async(dispatch_get_main_queue(), ^{ while([application backgroundTimeRemaining] &gt; 1.0) { //Do something.. } [application endBackgroundTask:self-&gt;bgTask]; self-&gt;bgTask = UIBackgroundTaskInvalid; NSLog(@"Ending background task...."); }); } </code></pre> <p>What should I do to complete a download asynchronously in background when the application goes to background?</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload