/** 前段时间iOS 健康数据非常的火,我忍不住寂寞,写了一个博客:
* @title: iOS利用HealthKit框架从健康app中获取步数信息
*
* 1.第一步首先需要开启HealthKit
* TARGETS -> Capabilities -> HealthKit -> YES
*
* 在此目录栏下,有一个steps,会显示一个❌(图片如下:health.png)
* eg:add 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