如何设置处理,以便我可以检测设备何时静止(在某个阈值中)
下面的代码没有按预期工作(userAcceleration 只是更大,取决于设备方向,用户甚至不移动设备(这个值可能来自重力))
self.motionManager = [[CMMotionManager alloc] init];
self.motionManager.accelerometerUpdateInterval = 1/2.0;
[self.motionManager startAccelerometerUpdatesToQueue:[NSOperationQueue currentQueue] withHandler:^(CMAccelerometerData *accelerometerData, NSError *error) {
float accelerationThreshold = 0.75;
CMAcceleration userAcceleration = accelerometerData.acceleration;
if ((fabs(userAcceleration.x) > accelerationThreshold)
|| (fabs(userAcceleration.y) > accelerationThreshold)
|| (fabs(userAcceleration.z) > accelerationThreshold)) {
self.deviceMoved = YES;
} else {
self.deviceMoved = NO;
}
}];