我已将健康工具包整合到我的项目中,当我只阅读8个健康工具包记录时,工作正常。现在我需要所有记录,但应用程序仅要求许可20个健康工具包类型标识符。
我们可以阅读所有健康套件数据吗? 是否需要任何特别许可?
这是我尝试的代码:
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
[self requestAuthorization];
}
- (void)requestAuthorization {
if ([HKHealthStore isHealthDataAvailable]) {
NSSet *writeDataTypes = [self dataTypesToWrite];
NSSet *readDataTypes = [self dataTypesToRead];
[self.healthStore requestAuthorizationToShareTypes:writeDataTypes readTypes:readDataTypes completion:^(BOOL success, NSError *error) {
if (!success) {
NSLog(@"You didn't allow HealthKit to access these read/write data types. In your app[][1]. The error was: %@.", error);
return;
}
}];
}
}
- (NSSet *)dataTypesToRead {
HKQuantityType *heightType = [HKObjectType quantityTypeForIdentifier:HKQuantityTypeIdentifierHeight];
HKQuantityType *weightType = [HKObjectType quantityTypeForIdentifier:HKQuantityTypeIdentifierBodyMass];
HKQuantityType *systolic = [HKObjectType quantityTypeForIdentifier:HKQuantityTypeIdentifierBloodPressureSystolic];
HKQuantityType *dystolic = [HKObjectType quantityTypeForIdentifier:HKQuantityTypeIdentifierBloodPressureDiastolic];
HKCategoryType *sleepAnalysis = [HKObjectType categoryTypeForIdentifier:HKCategoryTypeIdentifierSleepAnalysis];
HKQuantityType *step = [HKObjectType quantityTypeForIdentifier:HKQuantityTypeIdentifierStepCount];
HKQuantityType *walking = [HKObjectType quantityTypeForIdentifier:HKQuantityTypeIdentifierDistanceWalkingRunning];
HKQuantityType *cycling = [HKObjectType quantityTypeForIdentifier:HKQuantityTypeIdentifierDistanceCycling];
HKQuantityType *basalEnergyBurned = [HKObjectType quantityTypeForIdentifier:HKQuantityTypeIdentifierBasalEnergyBurned];
HKQuantityType *activeEnergyBurned = [HKObjectType quantityTypeForIdentifier:HKQuantityTypeIdentifierActiveEnergyBurned];
HKQuantityType *heartRate = [HKObjectType quantityTypeForIdentifier:HKQuantityTypeIdentifierHeartRate];
HKQuantityType *bodyTemp = [HKObjectType quantityTypeForIdentifier:HKQuantityTypeIdentifierBodyTemperature];
HKQuantityType *basalTemp = [HKObjectType quantityTypeForIdentifier:HKQuantityTypeIdentifierBasalBodyTemperature];
HKQuantityType *biotin = [HKObjectType quantityTypeForIdentifier:HKQuantityTypeIdentifierDietaryBiotin];
HKQuantityType *bloodalcohol = [HKObjectType quantityTypeForIdentifier:HKQuantityTypeIdentifierBloodAlcoholContent];
HKQuantityType *bloodGlucose = [HKObjectType quantityTypeForIdentifier:HKQuantityTypeIdentifierBloodGlucose];
HKQuantityType *bodyFat = [HKObjectType quantityTypeForIdentifier:HKQuantityTypeIdentifierBodyFatPercentage];
HKQuantityType *Caffeine = [HKObjectType quantityTypeForIdentifier:HKQuantityTypeIdentifierDietaryCaffeine];
HKQuantityType *Calcium = [HKObjectType quantityTypeForIdentifier:HKQuantityTypeIdentifierDietaryCalcium];
HKQuantityType *Carbohydrates = [HKObjectType quantityTypeForIdentifier:HKQuantityTypeIdentifierDietaryCarbohydrates];
HKQuantityType *CervicalMucusQuality = [HKObjectType quantityTypeForIdentifier:HKCategoryTypeIdentifierCervicalMucusQuality];
HKQuantityType *Chloride = [HKObjectType quantityTypeForIdentifier:HKQuantityTypeIdentifierDietaryChloride];
HKQuantityType *Chromium = [HKObjectType quantityTypeForIdentifier:HKQuantityTypeIdentifierDietaryChromium];
HKQuantityType *Copper = [HKObjectType quantityTypeForIdentifier:HKQuantityTypeIdentifierDietaryCopper];
HKQuantityType *DietaryEnergy = [HKObjectType quantityTypeForIdentifier:HKQuantityTypeIdentifierDietaryEnergyConsumed];
return [NSSet setWithObjects: heightType, weightType, systolic, dystolic, sleepAnalysis, step, walking, cycling, basalEnergyBurned, activeEnergyBurned, heartRate, bodyTemp, basalTemp, biotin, bloodalcohol, bloodGlucose, bodyFat, Caffeine, Calcium, Carbohydrates, CervicalMucusQuality, Chloride, Chromium, Copper, DietaryEnergy, nil];
}
答案 0 :(得分:1)
一旦应用程序提示某些类型的授权,在重置应用程序的授权之前,它不能再次提示这些类型。您可以通过两种方式重置授权: