CMDeviceMotion does not provide attitude info
For some reason my iPad2 is not providing motion attitude information. I am doing AFAIK precisely what people say to do but still... no data.
float angle = 0;
CMDeviceMotion *deviceMotion;
CMAttitude *attitude;
deviceMotion = motionManager.deviceMotion;
if (deviceMotion) {
attitude = deviceMotion.attitude;
[attitude multiplyByInverseO开发者_StackOverflow中文版fAttitude:referenceAttitude];
angle = [attitude roll];
} else {
NSLog (@"Cannot get angles.");
}
Earlier in my code I do this:
motionManager = [[CMMotionManager alloc] init];
if (motionManager.gyroAvailable) {
[motionManager startGyroUpdates];
}
However I never get the angle. Help?
You only get attitude if you use device motion updates, i.e. you have to call for initialisaiton:
if (![motionManager isDeviceMotionActive]) {
[motionManager startDeviceMotionUpdates];
}
And stopDeviceMotionUpdates
when going to background.
精彩评论