我已经在 iOS 6.0 和第 4 代 iPhone 和 iPod touch 上成功使用了 CMMotionManager。新 iPhone 5 的更新间隔似乎是指定的两倍。如果 kTIME_INTERVAL 为 0.0125,我看到的实际间隔约为 0.021。
当我将间隔设置为 0.0125 / 2.0 时,实际的计时器间隔接近 0.013,这正是我想要的。
有人在 iPhone 5 上看到与 CMMotionManager 类似的行为吗?
CMMotionManager *motion;
motion.deviceMotionUpdateInterval = kTIME_INTERVAL; // iPhone 4 and 4th gen devices
if (isDevice5thGeneration) {
// iPhone 5 iOS 6 seems to run motion at twice the update interval (half as fast), so need to set interval at half to get desired interval
motion.deviceMotionUpdateInterval = motion.deviceMotionUpdateInterval / 2.0; // iPhone 5 KLUDGE
}
NSLog(@"Start motion recording deviceMotionUpdateInterval: %f", motion.deviceMotionUpdateInterval);
NSOperationQueue *queue = [[NSOperationQueue currentQueue] retain];
CMDeviceMotionHandler motionHandler = ^(CMDeviceMotion *deviceMotion, NSError *error) {
//NSLog(@"motion handler");
if (isRecordingMotion) {
[self processMotion:deviceMotion];
}
};
[motion startDeviceMotionUpdatesToQueue:queue withHandler:motionHandler];
提前致谢!