ihpone5s 配置有M7协处理器,可以获得运动数据。计步功能
参考 https://developer.apple.com/library/prerelease/ios/documentation/CoreMotion/Reference/CoreMotion_Reference/index.html#//apple_ref/doc/uid/TP40009686
UILabel *label =[[UILabel alloc]initWithFrame:CGRectMake(0, 0, 320, 568/2)];
[label setBackgroundColor:[UIColor grayColor]];
label.textColor =[UIColor redColor];
label.textAlignment = NSTextAlignmentCenter;
[self.view addSubview:label];
if ([CMStepCounter isStepCountingAvailable]) {
NSLog(@"isStepCountingAvailable!!!");
NSOperationQueue *queueStep = [[NSOperationQueue alloc] init] ;
//20步数,更新一次
[_cmStepCounter startStepCountingUpdatesToQueue:queueStep updateOn:20 withHandler:^(NSInteger numberOfSteps, NSDate *timestamp, NSError *error) {
NSLog(@"numberOfSteps==%ld,timestamp==%@",(long)numberOfSteps,timestamp);
_steps = numberOfSteps;
label.text = [NSString stringWithFormat:@"%ld",_steps];
}];
}else{
NSLog(@"isNOT StepCountingAvailable");
}