Healthkit 权限限制为 20

Healthkit permission limit to 20

我已经将健康工具包集成到我的项目中,当我只读取 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];
}

一旦某个应用提示对某些类型进行授权,则在为该应用重置授权之前,它无法再次提示这些类型。您可以通过两种方式重置授权:

  1. 卸载并重新安装该应用程序。
  2. 点击“设置”>“通用”>“重置”中的“重置位置和隐私”按钮。