我想在Iphone的后台执行长时间运行的任务,但我用于后台任务的代码只执行3分钟
我的代码是
- (void)startService{
[self startBackgroundTask];
}
- (void) startBackgroundTask{
self.backgroundDataSendTimer = [NSTimer scheduledTimerWithTimeInterval:backgroundDataSendfrequency
target:self
selector:@selector(dobackgroundDataSendInBackground)
userInfo:nil
repeats:YES];
self.backgroundTask = [[UIApplication sharedApplication] beginBackgroundTaskWithExpirationHandler:^{
dispatch_async(dispatch_get_main_queue(), ^
{
if ( self.backgroundTask != UIBackgroundTaskInvalid)
{
[self endBackgroundTask];
self.backgroundTask = UIBackgroundTaskInvalid;
}
});
}];
- (void) endBackgroundTask{
[[UIApplication sharedApplication] endBackgroundTask:self.backgroundTask];
self.backgroundTask = UIBackgroundTaskInvalid;
[self startBackgroundTask];
}