简体   繁体   中英

how to run process in background in ios7

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.

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM