skip to Main Content

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


  1. check https://developer.apple.com/documentation/healthkit/authorizing_access_to_health_data

    To help protect the user’s privacy, your app doesn’t know whether the
    user granted or denied permission to read data from HealthKit. If the
    user denied permission, attempts to query data from HealthKit return
    only samples that your app successfully saved to the HealthKit store.

    Login or Signup to reply.
  2. 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.

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search