2

I want to run my process in fore ground and background continuously.I've implemented the following code

self.updateTimer = [NSTimer scheduledTimerWithTimeInterval:10.0
                                                    target:self
                                                  selector:@selector(repeatedMethod)
                                                  userInfo:nil
                                                   repeats:YES];

self.backgroundTask = [[UIApplication sharedApplication] beginBackgroundTaskWithExpirationHandler:^{
    NSLog(@"Background handler called. Not running background tasks anymore.");
    [[UIApplication sharedApplication] endBackgroundTask:self.backgroundTask];
    self.backgroundTask = UIBackgroundTaskInvalid;
}];

In foreground it is fine but in background process is running for just 5 mins and not running more than that.But I want it to run continuously even in background also.please help.

CodeSmile
  • 64,284
  • 20
  • 132
  • 217
Aruna M
  • 386
  • 3
  • 12

1 Answers1

1

Thats happening, because the completionHandler is called after 5 mins.You cannot run a background process for indefinite period in iOS until you use one of the UIBackgroundModes and that too is dependent upon you must provide a functionality of BackgroundMode if you use it in your application otherwise apple will reject it.

For example if you use "VoiP" BackgroundMode you application should provide "VoiP services" otherwise it will be rejected

hariszaman
  • 8,202
  • 2
  • 40
  • 59
  • I want location updates in background mode.Along with that I want to do some other task .Can it be possible – Aruna M Mar 31 '14 at 09:35
  • Also please provide some link to get continuous location updates. – Aruna M Mar 31 '14 at 09:35
  • yes, it is possible you should use "location" background mode as the apple documentation says about this background mode :"The app provides location-based information to the user and requires the use of the standard location services (as opposed to the significant change location service) to implement this feature." so, in xcode set the backgroundmode to "location" and see some tutorials on how to use that backgroundmode. Also look for "background-fetch" mode (available only in iOS7) – hariszaman Mar 31 '14 at 09:54
  • "You cannot run a background process for indefinite period in iOS until you use one of the" This is misleading, it makes it sound like you can run a background process for an indefinite period which is not the case. – Gruntcakes May 08 '14 at 16:47