sos の 作業メモ

プログラミングや英会話学習、マイルや旅行、日常生活など。最近はWebFormなASP.NETのお守りがお仕事です。

日々の生活にhappyをプラスする|ハピタス Gポイント

あれ?Attitudeも要るの?

前の記事で加速度の取得ができるようになったのですが、端末の傾き(pitchとroll)も必要だったことに気づき、それならCMDeviceMotion使えばいろんなデータとれるしってことで修正。

[_motionMgr startDeviceMotionUpdatesToQueue:[NSOperationQueue currentQueue] withHandler:^(CMDeviceMotion *motion, NSError *error) {
    if (motion && !error) {
        CMAttitude *att = motion.attitude;
        CMAcceleration gravity = motion.gravity;
        CMAcceleration useracc = motion.userAcceleration;
        // 一時バッファに格納
    }
}];

停止も修正

[_motionMgr stopDeviceMotionUpdates];
_motionMgr = nil;

簡単な修正で済んで助かりました。