美文网首页
iOS 步数获取

iOS 步数获取

作者: 清风_____ | 来源:发表于2022-01-17 14:11 被阅读0次

CMPedometer获取步数,获取的步数用户不能进行修改

第一步:配置info.plist里边的获取运动权限

<key>NSMotionUsageDescription</key>
<string>请允许使用运动健康</string>

image.png

第二步:引入头文件 #import <CoreMotion/CoreMotion.h>

#import <CoreMotion/CoreMotion.h>

@property (nonatomic, strong) CMPedometer * pedometer;
 第三步:获取步数

// 获取步数
-(void)getHealthStep
{
    if ([CMPedometer isStepCountingAvailable]) {
        _pedometer = [[CMPedometer alloc] init];
            
        NSDateFormatter *df = [[NSDateFormatter alloc] init];
        [df setDateFormat:@"yyyy-MM-dd"];
        NSString *yestr = [df stringFromDate:[NSDate date]];
        [df setDateFormat:@"yyyy-MM-dd HH:mm:ss"];
        //今天0点时间
        NSDate *d = [df dateFromString:[NSString stringWithFormat:@"%@ 00:00:00", yestr]];
        //查询0点到当前时间的数据
        [_pedometer queryPedometerDataFromDate:d toDate:[NSDate dateWithTimeIntervalSinceNow:0] withHandler:^(CMPedometerData * _Nullable pedometerData, NSError * _Nullable error) {

            if (error) {
                NSLog(@"error ===%@", error);
            }
            else {
                NSLog(@"步数====%@", pedometerData.numberOfSteps);
                NSLog(@"距离====%@", pedometerData.distance);
            }
        }];
    }
    else {
        NSLog(@"记步功能不可用");
    }
}

http://t.zoukankan.com/r360-p-14601236.html
https://www.jianshu.com/p/e5f332f9b27c

相关文章

  • iOS获取步数

    1. 请求权限 2. 请求步数

  • iOS 步数获取

    CMPedometer获取步数,获取的步数用户不能进行修改 第一步:配置info.plist里边的获取运动权限 <...

  • 初探HealthKit 获取步数

    [iOS] HealthKit 获取步数 前言 HealthKit 是苹果在 iOS 8.0 之后推出的健康框架,...

  • iOS 8 获取步数

    前言 上回说要给大家的陀螺仪的现在来了 这是运动项目里的一个步数获取的实现,在此之前不是是通过手机健康App的获取...

  • iOS开发——步数获取

    最近半个月的开发工作,重点一直是类似于悦跑圈、咕咚这样的运动产品的功能,所以在处理iOS设备在运动中的表现也是积累...

  • iOS 获取实时步数

    以下是个人理解,如有不对,轻喷: 网上给的大部分方法是调取系统的"健康"APP(HealthKit 库)的数据,但...

  • iOS HealthKit获取步数

    作为一个天天喊着减肥的资深女程序媛儿胖纸,对于减肥的APP还是十分关注的,尤其是运动步数排行榜,其实也只是看到步数...

  • iOS HealthKit 获取健康步数

    引入HealthKit库 创建 HKHealthStore

  • iOS 获取健康数据 步数

    最近的项目内容是给用户的健康数据做一个可视化的表格,现在把步数相关的统计查询之类的都已经完成了。其中遇到不少问题,...

  • iOS CMPedometer获取运动步数

    CMPedometer是iOS 8.0推出的,用来统计用户的的运动数据(步数、楼层、公里数等)。最近项目需...

网友评论

      本文标题:iOS 步数获取

      本文链接:https://www.haomeiwen.com/subject/npychrtx.html