Drishti
Drishti

Reputation: 13

Is there a way to get collective permission for multiple Data points from Healthkit

I am creating an application which needs to fetch heartRate, restingHeartRate, walkingHeartRateAverage, HeartRateVariabilitySDNN data from HealthKit.

Also I want to fetch user's body measurement data. i.e body mass index, body temperature, height, waist circumference, weight.

To get read permission I need to get separate permission for each data type:

let healthKitTypesToRead: Set<HKObjectType> = [
    HKObjectType.quantityType(forIdentifier: .heartRate)!,
    HKObjectType.quantityType(forIdentifier: .heartRateVariabilitySDNN)!,
    HKObjectType.quantityType(forIdentifier: .restingHeartRate)!,
    HKObjectType.characteristicType(forIdentifier: .walkingHeartRateAverage)!,
    HKObjectType.quantityType(forIdentifier: .bodyMass)!,
    HKObjectType.quantityType(forIdentifier: .bodyMassIndex)!,
    HKObjectType.quantityType(forIdentifier: .bodyTemperature)!,
    HKObjectType.quantityType(forIdentifier: .height)!,
    HKObjectType.quantityType(forIdentifier: .waistCircumference)!,
    HKObjectType.quantityType(forIdentifier: .weight)!,
] 

It shows multiple toggles on the permission screen, which I feel will be too much for the user to give individual permission to each. (in case they don't want to give all permissions.)

Is there a way to group the permissions or are there some dataTypes which if given permission will let us collect other dataTypes as well.

Initially I thought permission to heartRate meant I could fetch restingHeartRate, walkingHeartRateAverage, etc. But they all need their separate permissions.

Upvotes: 1

Views: 698

Answers (1)

pkamb
pkamb

Reputation: 34983

Each HealthKit type must be authorized independently:

To help protect the user’s privacy, HealthKit requires fine-grained authorization. You must request permission to both read and share each data type used by your app before you attempt to access or save the data.

https://developer.apple.com/documentation/healthkit/authorizing_access_to_health_data

Apple foresaw the difficulty of asking for many HealthKit types at once, and suggests to ask permission for different permission types at various times in your app rather than all at once:

However, you don’t need to request permission for all data types at once. Instead, it may make more sense to wait until you need to access the data before asking for permission.

The HealthHit permission dialog also does have a single button that allows the user to enable all requested types:

Turn All Categories On

Turn All Categories On

Upvotes: 0

Related Questions