当应用在iOS应用中转到后台时,NSTimer更新间隔会发生变化吗?

时间:2016-12-26 07:17:04

标签: ios nstimer nsrunloop

我通过CMDeviceMotion录制了NSTimer加速度数据样本30秒。问题是,当应用程序处于前台时,一切都很好。间隔设置为0.01,在30 seconds中,存储3000个读数。但是当应用程序进入后台时,我只会获得300个读数。

self.deviceMotionTimer = [NSTimer scheduledTimerWithTimeInterval:0.01 target:self selector:@selector(recordUpdates) userInfo:nil repeats:YES];

这是NSTimer的工作原理吗?

1 个答案:

答案 0 :(得分:0)

NSTimer永远不会在后台运作。当您的应用程序转到后台时,NSTimer也会冻结。简而言之,当您想在后台执行一些重复性任务时,您无法使用NSTimer。

如果您仍想在后台运行某些内容,请在此主题中使用@Robert给出的答案: Scheduled NSTimer when app is in background?