2016-12-26 56 views
0

我記錄了CMDeviceMotion加速度數據的樣本,持續30秒到NSTimer。事情是,當應用程序在前臺,一切都很好。間隔設置爲0.01,並在30 seconds,3000中存儲讀數。但是當應用程序進入後臺時,我只能得到300的讀數。當iOS應用程序轉到後臺時NSTimer更新間隔發生變化?

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

NSTimer是如何工作的?

回答

0

NSTimer將永遠不會在後臺工作。當你的應用程序進入後臺時,NSTimer也會凍結。總之,當你想在後臺執行一些重複任務時,你不能使用NSTimer。

如果你仍然想在後臺運行的東西,然後使用這個線程通過@Robert給出了答案: Scheduled NSTimer when app is in background?

相關問題