1

I am downloading large data from ASynchronous NSURLConnection in one separate viewcontroller.it takes 2 minutes to download the data.it works fine. but when i go to background mode through quitting Application,and open again , the splash screen comes and application closed forcely.when download small data, it works fine in background mode in same view controller.I use the follwing code after reading apple's finite length documnet. but it is not working?any help please?

 - (void)applicationDidEnterBackground:(UIApplication *)application
 {

    UIApplication  *app = [UIApplication sharedApplication];
    bgTask = [app beginBackgroundTaskWithExpirationHandler:^{ 
      [app endBackgroundTask:bgTask]; 
      bgTask = UIBackgroundTaskInvalid;
    }];

    dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{});

    [app endBackgroundTask:bgTask]; bgTask = UIBackgroundTaskInvalid;

}
nameless
  • 809
  • 3
  • 9
  • 27

1 Answers1

5

Yo need to do some of the works(like donloading) in multithreading concept. I think This is a very good tutorial and exactly mentions your problem(solves it too:) I hope it helps

EDIT: Apple says you can go on downloading in the background.

Background Tasks

Continuing a network transfer is an obvious

application of background tasks. If the user starts a large transfer and then switches out of your app, it can start a background task to continue the transfer. If all goes well the transfer will be finished before the user next brings the app to the front. When implementing background task support in your app, it's not necessary for you to have separate logic for the "in the background" and "in the foreground" cases.

ilhan çetin
  • 383
  • 5
  • 19
  • please see the http://stackoverflow.com/questions/4704037/download-data-in-background-with-ios4..why it is not working? it is not possible without THread? – nameless Feb 09 '12 at 14:29
  • Please can someone explain why minus? It is absolutely possible, look this too: https://developer.apple.com/library/ios/#samplecode/SeismicXML/Introduction/Intro.html – ilhan çetin Feb 09 '12 at 14:40