0

Again I have a similar doubt as specified in the link setKeepAliveTimeout and BackgroundTasks.

I have to periodically take a file from server and accordingly provide local notification. This has to be done when app is in background state.

Community
  • 1
  • 1
aparna
  • 353
  • 2
  • 3
  • 13
  • 2
    The only way to do something like this via a supported API is with push notifications. Regular apps can't do any downloads in the background for more than a few minutes. – hotpaw2 Feb 22 '13 at 09:05

1 Answers1

0

Create backgoud task in your interface:

@property (nonatomic) UIBackgroundTaskIdentifier bgTask;

Than create method to backgroud working:

- (void) backgroundMethod {

dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{

    //create backgriund task;
    self.bgTask = [[UIApplication sharedApplication] beginBackgroundTaskWithExpirationHandler:^{
        [[UIApplication sharedApplication] endBackgroundTask: self.bgTask];
        self.bgTask = UIBackgroundTaskInvalid;
    }];

    //do your stuff;
    [[UIApplication sharedApplication] endBackgroundTask: self.bgTask];
    self.bgTask = UIBackgroundTaskInvalid;
});
}

And call it whenewer you want periodicaly.

edzio27
  • 4,126
  • 7
  • 33
  • 48
  • thanks.. I tried the solution given in http://stackoverflow.com/questions/9220494/how-do-i-make-my-app-run-an-nstimer-in-the-background .. which was exactly what I need.. Thanks .. – aparna Feb 26 '13 at 10:18