EddyVerbruggen / HealthKit

Cordova plugin for the iOS HealthKit framework
MIT License
167 stars 215 forks source link

Active calories permission asked for even when energy not entered #25

Open flexed opened 9 years ago

flexed commented 9 years ago

Entering an activity like this:

window.plugins.healthkit.saveWorkout(
  {
    'activityType': 'HKWorkoutActivityTypeFishing',
    'quantityType': 'HKWorkoutTypeIdentifier',
    'requestReadPermission' : true, // set this if you don't need to read workouts as well
    'startDate': new Date(), // mandatory
    'endDate': null,         // optional, use either this or duration
    'duration': 60 * 60     // in seconds, optional, use either this or endDate
  },
  onSuccess,
  onError
);

Still requests the Active Calories data permission. I'm guessing it has to do with the code around line 162 of HealthKit.m:

 NSSet *types = [NSSet setWithObjects:[HKWorkoutType workoutType], [HKQuantityType quantityTypeForIdentifier:HKQuantityTypeIdentifierActiveEnergyBurned], [HKQuantityType quantityTypeForIdentifier:quantityType], nil];
[self.healthStore requestAuthorizationToShareTypes:types readTypes:requestReadPermission ? types : nil completion:^(BOOL success, NSError *error) {

Removing the "quantityTypeForIdentifier:HKQuantityTypeIdentifierActiveEnergyBurned" from that list works, but I know it will need to be optionally added back when people do use that value.

EddyVerbruggen commented 9 years ago

We could make it conditional based on whether or not we need it based on the input. Marking as enhancement.