Search code examples
ioshealthkit

HealthKit requestAuthorization returns code 100: "Authorization session timed out"


All of my HealthKit authorization requests are timing out with this error. Nothing in my code has changed, but I recently switched Xcode over to a new Apple ID account.

I have a development team setup, a provisioning profile configured, and the HealthKit Capability and Entitlement working. My app builds and runs fine, but any time I make a requestAuthorization call, I get a timeout for no apparent reason. There's no additional information in the error, and everything appears to be configured properly, so I'm pretty lost on what could cause this.

I've tried both simulators and devices with the same issue. The dialog for HealthKit auth never appears. I can go into the Health app after the fact and turn on the necessary data sharing, but this is a not an acceptable workaround.

What can cause healthKitStore requestAuthorization timeout errors?
I am 99% sure this is a configuration issue, but having gone through the process multiple times, and re-created numerous certs, provisioning profiles etc, I don't know what the problem could be. Where should I be looking for config issues? There is essentially zero documentation on this, and I've only found 2 results on Google related to this with no solutions.

let healthKitTypesToRead = [...]
let healthKitStore:HKHealthStore = HKHealthStore()

healthKitStore.requestAuthorization(toShare: nil, read: healthKitTypesToRead) { (success, error) -> Void in
    if( completion != nil ) {
        completion(success, error as? NSError)
    }
}

Solution

  • This was due to running the authorization request in a background thread. Doing it on the main thread solved the problem.