UIBackgroundTaskIdentifier taskId;//声明
- (void)applicationDidEnterBackground:(UIApplication *)application {//APP进入后台
//开启一个后台任务
taskId = [application beginBackgroundTaskWithExpirationHandler:^{
//结束指定的任务
[application endBackgroundTask:taskId];
}];
[self NABStartBackgroundTask];
}
-(void)NABStartBackgroundTask{
_count=0;
_Timer = [NSTimer scheduledTimerWithTimeInterval:1.0f target:self selector:@selector(countAdd) userInfo:nil repeats:YES];
}
-(void)countAdd{
_count++;
if (_count==120) {
[_Timer invalidate];
}
}
ios 解决NSTimer 进入后台循环失效
最新推荐文章于 2024-08-11 16:56:49 发布