LoginSignup
3
3

More than 5 years have passed since last update.

CMMotionManagerが動かないとき

Posted at
motion.m

@interface MotionTestViewController ()
@property(nonatomic, strong) CMMotionManager *motionManager;

@end

@implementation MotionTestViewController
@synthesize motionManager;

- (void)viewDidLoad
{
    motionManager = [[CMMotionManager alloc] init];
    // 加速度データの更新間隔を0.1秒ごとに設定
    motionManager.accelerometerUpdateInterval = 0.1;
    // 加速度センサが利用可能かチェック
    if (motionManager.accelerometerAvailable)
    {
        [motionManager startAccelerometerUpdatesToQueue:[NSOperationQueue currentQueue]
                                            withHandler:^(CMAccelerometerData *accelerometerData, NSError *error) { 
                                            NSLog(@"うごくよ");
                                            }];
    }
}

ちゃんとCMMotionManagerはインスタンス変数で定義しましょう。

ネットのソース拾うと結構ローカルで定義しているのが多かったので

3
3
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
3
3