本文主要是介绍iOS 获取健康里的信息(步数和公里数),希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!
//第一步
打开项目--点击capabilities 将HealthKit 打开 如下图
//第二步
1.首先新建一个类 -- 继承NSObject
在.h中
#define HKVersion [[[UIDevice currentDevice] systemVersion] doubleValue]
#define CustomHealthErrorDomain @"com.sdqt.healthError"
@interface HealthKitManage : NSObject
@property (nonatomic, strong) HKHealthStore *healthStore;
+(id)shareInstance;
- (void)authorizeHealthKit:(void(^)(BOOL success, NSError *error))compltion;
- (void)getDistance:(void(^)(double value, NSError *error))completion;
- (void)getStepCount:(void(^)(double value, NSError *error))completion;
+(id)shareInstance
{static id manager ;static dispatch_once_t onceToken;dispatch_once(&onceToken, ^{manager = [[[self class] alloc] init];});return manager;
}
- (void)authorizeHealthKit:(void(^)(BOOL success, NSError *error))compltion
{if(HKVersion >= 8.0){if (![HKHealthStore isHealthDataAvailable]) {NSError *error = [NSError errorWithDomain: @"com.raywenderlich.tutorials.healthkit" code: 2 userInfo: [NSDictionary dictionaryWithObject:@"HealthKit is not available in th is Device"
这篇关于iOS 获取健康里的信息(步数和公里数)的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!