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はインスタンス変数で定義しましょう。
ネットのソース拾うと結構ローカルで定義しているのが多かったので