Search code examples
iosswifthealthkit

HealthKit request authorization failing


I continue to receive this error when I request authorization.

Error Domain=com.apple.healthkit Code=5 "Transaction block failed without an error." UserInfo={NSLocalizedDescription=Transaction block failed without an error.}

I have tried re-adding and removing: Privacy - Health Update Usage Description, Privacy - Health Records Usage Description, Privacy - Health Share Usage Description

I have tried removing the HealthKit entitlement and adding it again. This flow worked previously, so I have no idea what is going on. Deleting and reinstalling app does not fix the problem either.

The HealthKit UI just never shows. Checking the privacy settings doesn't show I've ever requested either.

final class HealthStore {
    
    private let healthStore = HKHealthStore()

    func requestAuthorization() {
        let objectTypes: Set<HKObjectType> = [
            .activitySummaryType()
        ]
        
        healthStore.requestAuthorization(toShare: nil, read: objectTypes) { (success, error) in
            print("success = \(String(describing: success))")
            print("error = \(String(describing: error))")
        }
    }
}

In a sample application this code works just fine. I think HealthKit has gotten into a bad state.


Solution

  • I don't know the underlying problem, but restarting my Mac and my iPhone solved the problem.