HealthKit HKAuthorizationStatus读取数据

我正在使用HealthKit来读取某些types的信息。 我特别不要求写function。 尝试检测用户是否允许读取某个健康types时,会出现问题。

我相信这样做的预期方法是使用HKHealthStore的authorizationStatusForType方法,但是这只会返回被拒绝或未知。 它只是返回授权的写入types。 有没有人find一种方法来使用这种方法阅读或另一个工作?

HKQuantityType *stepsType = [HKQuantityType quantityTypeForIdentifier:HKQuantityTypeIdentifierHeight]; HKAuthorizationStatus status = [self.healthStore authorizationStatusForType:stepsType]; 

出于隐私的原因,您无法查看您的应用程序的读取特定types的授权状态。

  NSArray *quantityTypesUsedInApp = @[HKQuantityTypeIdentifierBodyMass, HKQuantityTypeIdentifierHeight, HKQuantityTypeIdentifierBodyMassIndex, HKQuantityTypeIdentifierBodyFatPercentage, HKQuantityTypeIdentifierLeanBodyMass]; for (NSString *identifier in quantityTypesUsedInApp) { HKQuantityType *sampleType = [HKQuantityType quantityTypeForIdentifier:identifier]; NSSet *requestSampleUnit = [NSSet setWithObject:sampleType]; [self.healthKitStore preferredUnitsForQuantityTypes:requestSampleUnit completion:^(NSDictionary *preferredUnits, NSError *error) { if (!error) { HKUnit *unit = [preferredUnits objectForKey:sampleType]; NSLog(@"%@ : %@", sampleType.identifier, unit.unitString); //sampleType enabled for read } else { switch (error.code) { case 5: NSLog(@"%@ access denied", sampleType.identifier); //sampleType denied for read break; default: NSLog(@"request preffered quantity types error: %@", error); break; } } }]; }