EddyVerbruggen / HealthKit

Cordova plugin for the iOS HealthKit framework
MIT License
168 stars 216 forks source link

Authorization to share the following types is disallowed #106

Closed awatson1978 closed 5 years ago

awatson1978 commented 5 years ago

Has anyone seen an error message similar to the following?

Terminating app due to uncaught exception 'NSInvalidArgumentException', 
reason: 'Authorization to share the following types is disallowed: 
HKClinicalTypeIdentifierProcedureRecord, HKClinicalTypeIdentifierVitalSignRecord, HKClinicalTypeIdentifierMedicationRecord, HKClinicalTypeIdentifierAllergyRecord, HKClinicalTypeIdentifierImmunizationRecord, HKClinicalTypeIdentifierLabResultRecord, HKClinicalTypeIdentifierConditionRecord'

screen shot 2018-12-02 at 9 34 09 am

NSHealthShareUsageDescription and NSHealthUpdateUsageDescription are both set correctly.

The relevant code block is the following:

importChart(){
    console.log('importChart', window.plugins)

      window.plugins.healthkit.available(
          callback,
          callback
      );
      var supportedTypes = [
        'HKQuantityTypeIdentifierHeight',
        'HKClinicalTypeIdentifierAllergyRecord',
        'HKClinicalTypeIdentifierConditionRecord',
        'HKClinicalTypeIdentifierImmunizationRecord',
        'HKClinicalTypeIdentifierLabResultRecord',
        'HKClinicalTypeIdentifierMedicationRecord',
        'HKClinicalTypeIdentifierProcedureRecord',
        'HKClinicalTypeIdentifierVitalSignRecord'
    ];
      // or any of these HKClinicalType for readTypes 
      window.plugins.healthkit.requestAuthorization(
          {
            readTypes: supportedTypes,
            writeTypes: supportedTypes
          },
          function(){alert('ok')},
          function(){alert('nok')}
      );

      window.plugins.healthkit.queryForClinicalRecordsWithFHIRResourceType(
        {
          fhirResourceType: 'HKFHIRResourceTypeCondition',
          sampleType: 'HKClinicalTypeIdentifierConditionRecord'
          // or any of these other HKFHIRResourceType
          // HKFHIRResourceTypeAllergyIntolerance',
          // HKFHIRResourceTypeImmunization
          // HKFHIRResourceTypeMedicationDispense
          // HKFHIRResourceTypeMedicationOrder
          // HKFHIRResourceTypeMedicationStatement
          // HKFHIRResourceTypeObservation
          // HKFHIRResourceTypeProcedure
          // or any of these other HKClinicalType
          // HKClinicalTypeIdentifierImmunizationRecord
          // HKClinicalTypeIdentifierLabResultRecord
          // HKClinicalTypeIdentifierMedicationRecord
          // HKClinicalTypeIdentifierProcedureRecord
          // HKClinicalTypeIdentifierVitalSignRecord
        },
        function(data){
          console.log('HKFHIRResourceTypeCondition.ok', data)
        },
        function(){console.log('HKFHIRResourceTypeCondition.nok')}
      );

  }
awatson1978 commented 5 years ago

Oh, you know what.... this is using queryForClinicalRecordsWithFHIRResourceType and is specific to PR #104

awatson1978 commented 5 years ago

Ah, figured it out. There's a third key that needs to be set into the .plist file: NSHealthClinicalHealthRecordsShareUsageDescription.

screen shot 2018-12-02 at 10 00 42 am

qaliwebguru commented 3 years ago

I have added NSHealthClinicalHealthRecordsShareUsageDescription but still getting the following issue.

Foundation.MonoTouchException: Objective-C exception thrown. Name: NSInvalidArgumentException Reason: Authorization to read the following types is disallowed: HKClinicalTypeIdentifierMedicationRecord, HKClinicalTypeIdentifierConditionRecord, HKClinicalTypeIdentifierProcedureRecord, HKClinicalTypeIdentifierVitalSignRecord, HKClinicalTypeIdentifierImmunizationRecord, HKClinicalTypeIdentifierAllergyRecord, HKClinicalTypeIdentifierLabResultRecord

dattatrayParthenon commented 3 years ago

@qaliwebguru you may have not enabled HealthKit capability.