开发者

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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜