Reputation: 107
I'm attempting to read step data for just a single day using HealthKit. HK thinks that I'm somehow trying to write to it as well, even though there is nothing in my code that writes or requests HK write authorization.
This is the code I use for the request:
let healthKitTypes: Set = [
HKObjectType.quantityType(forIdentifier: HKQuantityTypeIdentifier.stepCount)!
]
healthStore.requestAuthorization(toShare: healthKitTypes, read: healthKitTypes) { (isSuccess, error) in
if isSuccess {
UserDefaults.standard.set(true, forKey: "isHKAuthorized")
} else { UserDefaults.standard.set(false, forKey: "isHKAuthorized") }
if let error = error {
UserDefaults.standard.set(false, forKey: "isHKAuthorized")
print(error.localizedDescription)
}
}
How can I get HK to stop bugging me about write permission? The auth UI should only be asking for read data.
Upvotes: 0
Views: 143
Reputation: 2676
The auth request says, "toShare" but it means writing. So set the toShare parameter to nil or an empty set.
Upvotes: 1