-(void)play
{
CMMotionManager *motionManager = [[CMMotionManager alloc] init];
[motionManager startDeviceMotionUpdates];
while(!self.stopButtonPressed)
{
NSLog(@"Y-Axis acceleration is %f", motionManager.deviceMotion.userAcceleration.y);
}
}
控制台:
2012-08-03 13:06:10.798 MyProject[8896:3a03] Y-Axis acceleration is 0.000000
2012-08-03 13:06:10.803 MyProject[8896:3a03] Y-Axis acceleration is 0.000000
2012-08-03 13:06:10.805 MyProject[8896:3a03] Y-Axis acceleration is 0.000000
2012-08-03 13:06:10.807 MyProject[8896:3a03] Y-Axis acceleration is 0.000000
2012-08-03 13:06:10.808 MyProject[8896:3a03] Y-Axis acceleration is 0.000000
2012-08-03 13:06:10.810 MyProject[8896:3a03] Y-Axis acceleration is 0.000000
2012-08-03 13:06:10.812 MyProject[8896:3a03] Y-Axis acceleration is 0.000000
2012-08-03 13:06:10.814 MyProject[8896:3a03] Y-Axis acceleration is 0.000000
2012-08-03 13:06:10.817 MyProject[8896:3a03] Y-Axis acceleration is 0.013498
2012-08-03 13:06:10.820 MyProject[8896:3a03] Y-Axis acceleration is 0.013498
2012-08-03 13:06:10.822 MyProject[8896:3a03] Y-Axis acceleration is 0.013498
2012-08-03 13:06:10.824 MyProject[8896:3a03] Y-Axis acceleration is 0.013498
2012-08-03 13:06:10.826 MyProject[8896:3a03] Y-Axis acceleration is 0.013498
2012-08-03 13:06:10.828 MyProject[8896:3a03] Y-Axis acceleration is 0.013498
2012-08-03 13:06:10.831 MyProject[8896:3a03] Y-Axis acceleration is -0.082339
2012-08-03 13:06:10.833 MyProject[8896:3a03] Y-Axis acceleration is -0.082339
2012-08-03 13:06:10.835 MyProject[8896:3a03] Y-Axis acceleration is -0.082339
2012-08-03 13:06:10.837 MyProject[8896:3a03] Y-Axis acceleration is -0.082339
2012-08-03 13:06:10.840 MyProject[8896:3a03] Y-Axis acceleration is -0.082339
2012-08-03 13:06:10.842 MyProject[8896:3a03] Y-Axis acceleration is -0.082339
2012-08-03 13:06:10.846 MyProject[8896:3a03] Y-Axis acceleration is -0.099570
2012-08-03 13:06:10.848 MyProject[8896:3a03] Y-Axis acceleration is -0.099570
2012-08-03 13:06:10.850 MyProject[8896:3a03] Y-Axis acceleration is -0.099570
2012-08-03 13:06:10.852 MyProject[8896:3a03] Y-Axis acceleration is -0.099570
2012-08-03 13:06:10.855 MyProject[8896:3a03] Y-Axis acceleration is -0.099570
2012-08-03 13:06:10.857 MyProject[8896:3a03] Y-Axis acceleration is -0.099570
2012-08-03 13:06:10.859 MyProject[8896:3a03] Y-Axis acceleration is -0.120698
2012-08-03 13:06:10.862 MyProject[8896:3a03] Y-Axis acceleration is -0.120698
2012-08-03 13:06:10.864 MyProject[8896:3a03] Y-Axis acceleration is -0.120698
2012-08-03 13:06:10.866 MyProject[8896:3a03] Y-Axis acceleration is -0.120698
2012-08-03 13:06:10.868 MyProject[8896:3a03] Y-Axis acceleration is -0.120698
2012-08-03 13:06:10.870 MyProject[8896:3a03] Y-Axis acceleration is -0.120698
2012-08-03 13:06:10.873 MyProject[8896:3a03] Y-Axis acceleration is -0.125984
2012-08-03 13:06:10.875 MyProject[8896:3a03] Y-Axis acceleration is -0.125984
2012-08-03 13:06:10.877 MyProject[8896:3a03] Y-Axis acceleration is -0.125984
2012-08-03 13:06:10.879 MyProject[8896:3a03] Y-Axis acceleration is -0.125984
2012-08-03 13:06:10.881 MyProject[8896:3a03] Y-Axis acceleration is -0.125984
2012-08-03 13:06:10.882 MyProject[8896:3a03] Y-Axis acceleration is -0.125984
2012-08-03 13:06:10.884 MyProject[8896:3a03] Y-Axis acceleration is -0.125984
2012-08-03 13:06:10.888 MyProject[8896:3a03] Y-Axis acceleration is -0.083223
....etc.
根据控制台,加速度值平均每14微秒更新一次
我没有明确地使用具有更新间隔的队列,所以我应该假设默认更新间隔大约是14微秒(当我在这个代码中具体地询问来自while循环内部的新值时)?
或者这是“意外”,我不应该依赖它?我的意思是我已经测试了几次,更新间隔总是在13-14毫秒之间,但是有可能(如果我没有明确地设置更新间隔),如果处理器,更新间隔会在稍后的某些测试中发生显着变化由于某种原因,恰好比较“忙碌”(通常......)......?
感谢您的帮助
答案 0 :(得分:1)
您不应该依赖此间隔,因为UIAccelerometer类引用 - 最大更新间隔基于可用硬件,因此当Apple将在未来设备中更新Accelerometer芯片时,频率可能会发生变化(也可能是在当前的iPad和iPhone上有所不同)