iOS开发 CoreMotion 获取当前运动状态 步行/跑步/自行车/驾车 CMMotionActivityManager


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 = @"准确度  高";
         }
         
     }];

  • 1
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值