I would like to request the HealthKit data here, but I keep getting a lot of error messages from the compiler. Does anyone know what the problem is here? Here is the code:
let healthStore = HKHealthStore()
let allTypes = Set([HKObjectType.workoutType(),
HKObjectType.quantityType(forIdentifier: .activeEnergyBurned)!,
HKObjectType.quantityType(forIdentifier: .distanceCycling)!,
HKObjectType.quantityType(forIdentifier: .distanceWalkingRunning)!,
HKObjectType.quantityType(forIdentifier: .heartRate)!])
healthStore.requestAuthorization(toShare: allTypes, read: allTypes) { (success, error) in
if !success {
// Handle the error here.
}
}
I used the Apple Developer Documentation and did all exactly like it was written. Obviously, it didn't worked. Does anyone know the solution? Thank you very much in advance.
Before requesting HealthKit data you need to set usage description entries in your apps plist.
https://developer.apple.com/documentation/healthkit/hkhealthstore/1614152-requestauthorization#discussion
on top of that, you also need to add
HealthKitin your app capabilities/entitlements otherwise you will getError: Missing com.apple.developer.healthkit entitlement.