首先需要打开Xcode->Target->Capabilities
然后导入<HealthKit/HealthKit.h>
因为苹果健康数据有很多。所以我们只需要获取我们我们需要的数据,所有的数据类型都以字符串表示,保存在HKTypeIdentifiers.h中
这里我以步数为例。为HKQuantityTypeIdentifierStepCount
本例获取当天的步数统计
//判断健康是否可用
if ([HKHealthStore isHealthDataAvailable]) {
self.healthStore = [[HKHealthStore alloc] init];
//需要写入的数据
self.stepType = [HKSampleType quantityTypeForIdentifier:HKQuantityTypeIdentifierStepCount];
//需要读取的数据
self