我设置了一个Timer(),每0.01秒更新一次MotionActivity的数据,但它每3到4秒更新一次。为什么呢?
timer = Timer.scheduledTimer(timeInterval: 0.01, target: self, selector: #selector(ViewController.updateWatch), userInfo: nil, repeats: true)
func updateWatch() {
if CMMotionActivityManager.isActivityAvailable() {
activtyManager.startActivityUpdates(to: OperationQueue.main, withHandler: { (data: CMMotionActivity!) in
print(data)
if data.stationary == false { some code } }) } else { print("error") }