1、iOS7 或更高版本
2、需要 手机 有 协处理器 (5S 或 以后的设备 )
3、可以检查到 五种状态 ,静止,步行 ,跑步,自行车,驾车
4、每次回调结果 ,都有 本次结果准确程度的 描述 低 ,中 ,高 三个等级
#import <CoreMotion/CoreMotion.h> self.motionActivityManager=[[CMMotionActivityManager alloc]init];
self.dateFormater = [[NSDateFormatter alloc] init];
self.dateFormater.dateFormat = @"yyyy-MM-dd HH:mm:ss";
__weak typeof (self)weakSelf = self;
[self.motionActivityManager startActivityUpdatesToQueue:[NSOperationQueue mainQueue] withHandler:^(CMMotionActivity *activity)
{
weakSelf.timeStampLabel.text = [weakSelf.dateFormater stringFromDate:[NSDate date]];
if (activity.unknown) {
weakSelf.currentStateLabel.text = @"未知状态";
} else if (activity.walking) {
weakSelf.currentStateLabel.text = @"步行";
} else if (activity.running) {
weakSelf.currentStateLabel.text = @"跑步";
} else if (activity.automotive) {
weakSelf.currentStateLabel.text = @"驾车";
} else if (activity.stationary) {
weakSelf.currentStateLabel.text = @"静止";
}
if (activity.confidence == CMMotionActivityConfidenceLow) {
weakSelf.confidenceLabel.text = @"准确度 低";
} else if (activity.confidence == CMMotionActivityConfidenceMedium) {
weakSelf.confidenceLabel.text = @"准确度 中";
} else if (activity.confidence == CMMotionActivityConfidenceHigh) {
weakSelf.confidenceLabel.text = @"准确度 高";
}
}];