3

I'm running into an occasional (not every time) error when attempting to load workout data from HealthKit on the iPhone: Error Domain=com.apple.healthkit Code=6 "Protected health data is inaccessible" {NSLocalizedDescription=Protected health data is inaccessible}

The only other references to this error I've found is when attempting to access HealthKit data when the phone is locked But I am attempting to load the data with the phone unlocked. Any other idea what the issue could be?

My HealthKit Permissions:

private func requestAccessToHealthKit() {
        let healthStore = HKHealthStore()

        let healthKitTypesToWrite: Set<HKSampleType> = [HKObjectType.workoutType(),
            HKSeriesType.workoutRoute(),
            HKObjectType.quantityType(forIdentifier: .activeEnergyBurned)!,
            HKObjectType.quantityType(forIdentifier: .heartRate)!,
            HKObjectType.quantityType(forIdentifier: .restingHeartRate)!,
            HKObjectType.quantityType(forIdentifier: .bodyMass)!,
            HKObjectType.quantityType(forIdentifier: .vo2Max)!,
            HKObjectType.quantityType(forIdentifier: .stepCount)!,
            HKObjectType.quantityType(forIdentifier: .distanceWalkingRunning)!]

        let healthKitTypesToRead: Set<HKObjectType> = [
            HKObjectType.workoutType(),
            HKSeriesType.workoutRoute(),
            HKObjectType.quantityType(forIdentifier: .activeEnergyBurned)!,
            HKObjectType.quantityType(forIdentifier: .heartRate)!,
            HKObjectType.quantityType(forIdentifier: .restingHeartRate)!,
            HKObjectType.characteristicType(forIdentifier: .dateOfBirth)!,
            HKObjectType.quantityType(forIdentifier: .bodyMass)!,
            HKObjectType.quantityType(forIdentifier: .vo2Max)!,
            HKObjectType.quantityType(forIdentifier: .stepCount)!,
            HKObjectType.quantityType(forIdentifier: .distanceWalkingRunning)!]


        healthStore.requestAuthorization(toShare: healthKitTypesToWrite, read: healthKitTypesToRead) { (success, error) in
            if !success {
                print("failed HealthKit Authorization from iPhone \(String(describing: error?.localizedDescription))")
            }

            print("Successful HealthKit Authorization from iPhone")
        }
    }
GarySabo
  • 5,806
  • 5
  • 49
  • 124
  • I am facing similar issue occasionally. Did you find anything on this? – Adeesh Jain Mar 24 '18 at 04:57
  • 1
    @AdeeshJain I haven't...it only seems to come up every so often. Let me know if you figure anything out. – GarySabo Mar 24 '18 at 13:32
  • I've a sporadic error like that. The strange thing is that once received HealthKit data is completely locked down from watchOS. Couldn't access data, even if authorization status return true. – valvoline Mar 22 '19 at 08:58

0 Answers0