我已经尝试过,但在 iOS 7 和 Xcode 4.6.2 中工作时间不超过 180 秒。请帮我
UIBackgroundTaskIdentifier bgTask = UIBackgroundTaskInvalid;
UIApplication *app = [UIApplication sharedApplication];
bgTask = [app beginBackgroundTaskWithExpirationHandler:^{
[app endBackgroundTask:bgTask];
}];
NSTimer *timer = [NSTimer scheduledTimerWithTimeInterval:20 target:self selector:@selector(timerMethod) userInfo:nil repeats:YES];
[[NSRunLoop currentRunLoop] addTimer:timer forMode:NSRunLoopCommonModes];
-(void) timerMethod{
NSLog(@"in timerMethod");
}
除非您启用其中一项Background modes
,这是行不通的。
Why?
有一些解决方法,请考虑检查以下问题:
iphone - NSTimers 在后台 https://stackoverflow.com/questions/8943214/iphone-nstimers-in-background?rq=1
当应用程序在后台时安排 NSTimer? https://stackoverflow.com/questions/8415870/scheduled-nstimer-when-app-is-in-background?lq=1
后台 NSTimer 正在工作 https://stackoverflow.com/questions/5187741/nstimer-on-background-is-working/17445679
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)