I have an application that previously only requested these HealthKit authorizations:
if let heartRateQuantityType = HKQuantityType.quantityType(forIdentifier: .heartRate) {
self.heartRateQuantityType = heartRateQuantityType
} else {
fatalError("* Unable to get the heartRate type *")
}
if let calorieQuantityType = HKQuantityType.quantityType(forIdentifier: .activeEnergyBurned) {
self.calorieQuantityType = calorieQuantityType
} else {
fatalError("* Unable to get the activeEnergyBurned type *")
}
let typesToShare: Set = [
HKQuantityType.workoutType()
]
let typesToRead: Set = [
	heartRateQuantityType,
calorieQuantityType
]
However, I later decided I wanted to be able to delete calorie data. I am now trying to add calorieQuantityType as a typeToShare, but it is not working.
let typesToShare: Set = [
HKQuantityType.workoutType(),
calorieQuantityType
]
let typesToRead: Set = [
	heartRateQuantityType,
calorieQuantityType
]
healthStore.requestAuthorization(toShare: typesToShare, read: typesToRead) { (success, error) in
if let error = error {
print(error.localizedDescription)
}
}
For some reason the app requests HealthKit authorization on every app start, and the permission doesn't work. The toggle also does not show in the Health section of the watch settings. If I reinstall the app, it does work. This obviously isn't okay from an end-user's perspective. Is this possible to work around, or is this a bug?
Post
Replies
Boosts
Views
Activity
I have code that's been in production for a year and never had any issues reading BMI. One of my users just submitted a bug report saying that attempting to read BMI data crashed the app. The error Xcode shows is 'Attempt to convert incompatible units: count, kg/m^2'. Now I'm pretty sure the unit for BMI shouldn't be "count" so what the heck is going on? Is this a bug? This is happening on watchOS 9.5.2.
Please note that this app version was released to the App Store a year ago and worked at that time (and presumable until recently).