iosswifthealthkit

How to request HealthKit permissions for Scored Assessments (GAD-7/PHQ-7)?


In iOS 18.0 there is new HK type - HKScoredAssessment (subclassed by HKGAD7Assessment and HKPHQ9Assessment). When trying to save it to HealthKit I don't see how one can request authorization for it. By looking at the documentation it only seems like they added stateOfMindType() in iOS 18 (on HKObjectType).


Solution

  • It might not be that obvious since almost all other types have convenience methods (such as stateOfMindType()) or can be accessed by quantity/category type.

    As it comes to the scored assessments it's possible create a HKObjectType by using HKScoredAssessmentType and passing the needed identifier. e.g.:

    let type: HKObjectType = HKScoredAssessmentType(.GAD7)
    

    Screenshot of Health Access with scored assessments permissions