Reputation: 73
I have integrated health kit into my project and it was working fine, when I read only 8 health kit records. Now I need all the records, but the application asks permission for only 20 health kit type identifiers.
Can we read all the health kit data? Does it need any special permission?
Here my code which i tried:
- (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];
}
Upvotes: 1
Views: 303
Reputation: 7353
Once an app has prompted for authorization for some types, it cannot prompt again for those types again until authorization is reset for the app. There are two ways you can reset authorization:
Upvotes: 1