iOS利用HealthKit框架从健康app中获取步数信息

/** 前段时间iOS 健康数据非常的火,我忍不住寂寞,写了一个博客:

 * @title: iOS利用HealthKit框架从健康app中获取步数信息

 *

 *  1.第一步首先需要开启HealthKit

 *  TARGETS -> Capabilities -> HealthKit -> YES

 *

 *  在此目录栏下,有一个steps,会显示一个(图片如下:health.png)

 *  egadd the "HealthKit" entitlement to your app id

 *  这是 你可能需要Fix issue ,这时候可能会在项目中出现.entitlements 文件

 *  相关处理请自行查资料直到ok为止

 *

 *  2.新建一个HealthKitManage类,继承于NSObject

 *    (1)导入头文件

 *    #import <HealthKit/HealthKit.h>

 *    #import <UIKit/UIKit.h>

 *    #define HKVersion [[[UIDevice currentDevice] systemVersion] doubleValue]

 *    #define CustomHealthErrorDomain @"com.sdqt.healthError

 *  相关的方法请自行查看 HealthKitManage.h  & HealthKitManage.m  文件(已封装)

 *

 *  3.相关的调用

 *    HealthKitManage *manage = [HealthKitManage shareInstance];

 *    然后调用相关的方法(对象 方法名)

 *

 *  4.参考博客:http://www.jianshu.com/p/1dd6ad5b1520


 */


下面直接上代码:


#import <Foundation/Foundation.h>

#import <HealthKit/HealthKit.h>

#import <UIKit/UIKit.h>


@interface HealthKitManage : NSObject


@property(nonatomic,strong)HKHealthStore *healthStore;


/**

 *  2.创建单例

 */

+(id)shareInstance;


/*

 *  3.检查是否支持获取健康数据

 *  @brief  检查是否支持获取健康数据

 */

- (void)authorizeHealthKit:(void(^)(BOOL success, NSError *error))compltion;


/*

 *  4.获取步数

 */

- (void)getStepCount:(void(^)(double value, NSError *error))completion;


/**

 *  5.获取公里数

 *  读取步行+跑步距离

 */

- (void)getDistance:(void(^)(double value, NSError *error))completion;


@end



//

//  HealthKitManage.m

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值