So I have an watchOS
app where users can track their outdoor activities and that includes heartrate. All of that is working fine, but in support we sometimes get users that complain that the app is not tracking their heartrate. And in almost all the cases the missing READ permission for heartrate is the problem. Now I’d like to add a little hint inside the app, that this permission is missing so that the users will know and hopefully be able to fix the problem on their own.
The only problem now… How?
I tried the following way:
let healthStore = HKHealthStore()
let heartRateType = HKObjectType.quantityType(forIdentifier: .heartRate)!
let authStatus = healthStore.authorizationStatus(for: heartRateType)
// authStatus will be .sharingAuthorized even WITHOUT read permissions and only write permissions given
but that only gives me the SHARE-permission status. I want the READ-permission status.
So when in settings I allow writing of heartrate but decline reading of it, this authStatus
is still authorized.
Also just trying to start my HKAnchoredObjectQuery
will NOT give me an error
in the result handler. It will be called once (like it would if I had given the permission) but only with empty samples. But I would have expected an error saying I have no permissions?!? But that’s not the case.
So my final question: Is there a way to tell if I have the READ permission for heartrate on watchOS
using HealthKit
?
2
Answers
check https://developer.apple.com/documentation/healthkit/authorizing_access_to_health_data
all the apps that use Healthkit like Nike and others, just check the write permission to Healthkit, but permission is requested for all types. I agree with the previous post about it. Majority of users in my experience just give all permissions or do not give any. That is the only way you can probably check for the permission, or you can file a request to Apple. However they will probably leave it as it is.