I am writing an Apple WatchOS app which needs the user's heart rate. However, I am not able to get the HealthKit permissions sheet to appear. The watch and iPhone display a notification saying that my app would like to access the health data, but a permissions sheet does not appear, and even using the health app is does not show that my app has requested permission for any of the data.
I have looked on multiple questions already and there does not appear to be an answer online. I have tried several different online tutorials for HealthKit and this is the only one that has compiled so far. I have Privacy - Health Records Usage Description
and Privacy - Health Share Usage Description
in my info.plist for both ios and watch targets. I have also turned on HealthKit in the capabilities of both targets. My code is:
func requestHealthAuthorization() {
let heartRate = HKObjectType.quantityType(forIdentifier: .heartRate)!
let distance = HKObjectType.quantityType(forIdentifier: .distanceWalkingRunning)!
let types: Set<HKSampleType> = [heartRate, distance]
store.requestAuthorization(toShare: types, read: types) { (success, error) in
guard success else {
return
}
self.heartRateQuery = self.getHeartRate()
self.store.execute(self.heartRateQuery!)
}
}
I am expecting a HealthKit request sheet to pop up but instead, nothing is happening. If I print out the success and error values I get:
success = false
error = Optional(Error Domain=com.apple.healthkit Code=5 "Authorization request canceled" UserInfo={NSLocalizedDescription=Authorization request canceled})
Any help you be great. Thanks.