HealthKit.RequestAuthorizationToShareTypes
------------------------------------------

Requests authorization from the user.

| Component | Version | macOS | Windows | Linux | Server | iOS SDK |
|---|---|---|---|---|---|---|
| [HealthKit](component_HealthKit.md) | [8.2](newinversion82.md) | ❌ No | ❌ No | ❌ No | ❌ No | ✅ Yes |

MBS( "HealthKit.RequestAuthorizationToShareTypes"; ShareList; ReadList { ; FileName; ScriptName } ) 

**MBS**( **"HealthKit.RequestAuthorizationToShareTypes";** /\* Requests authorization from the user. \*/  
**$ShareList**; /\* The list of sample types to share.  
Can be empty if you just read.e.g. "" \*/   
**$ReadList**; /\* The list of object types to read.e.g. "BiologicalSex¶BloodType" \*/   
**$FileName**; /\* Optional; The file name of the script to call.e.g. Get(FileName) \*/   
**$ScriptName**) /\* Optional; The name of the script to trigger.e.g. "AuthorizationCompleted" \*/ 

### Parameters

| Parameter | Description | Example | Flags |
|---|---|---|---|
| ShareList | The list of sample types to share.   Can be empty if you just read. | "" |  |
| ReadList | The list of object types to read. | "BiologicalSex¶BloodType" |  |
| FileName | The file name of the script to call. | Get(FileName) | Optional |
| ScriptName | The name of the script to trigger. | "AuthorizationCompleted" | Optional |

### Result

Returns OK or error.

### Description

Requests authorization from the user.  
Prompts the user to authorize the application for reading and saving objects of the given types.  
Before attempting to execute queries or save objects, the application should first request authorization from the user to read and share every type of object for which the application may require access.  
The request is performed asynchronously and its completion will be executed on an arbitrary background queue after the user has responded. If the user has already chosen whether to grant the application access to all of the types provided, then the completion will be called without prompting the user.  
  
We call optionally your script to pass in the result. You get a list of values. First entry is Success or Cancel. Second value is the error message.  
The success parameter of the completion indicates whether prompting the user, if necessary, completed successfully and was not cancelled by the user. It does NOT indicate whether the application was granted authorization.  
  
To customize the messages displayed on the authorization sheet, set the following keys in your app's Info.plist file. Set the NSHealthShareUsageDescription key to customize the message for reading data.  
Set the NSHealthUpdateUsageDescription key to customize the message for writing data.  
  
Supported quantity types:  
  
- Body Measurements: BodyFatPercentage, BodyMass, BodyMassIndex, Height, LeanBodyMass, WaistCircumference.
- Fitness: StepCount, DistanceWalkingRunning, DistanceCycling, DistanceWheelchair, BasalEnergyBurned, ActiveEnergyBurned, FlightsClimbed, NikeFuel, AppleExerciseTime, PushCount, DistanceSwimming, SwimmingStrokeCount, VO2Max.
- Vitals: HeartRate, BodyTemperature, BasalBodyTemperature, BloodPressureSystolic, BloodPressureDiastolic, RespiratoryRate.
- Results: OxygenSaturation, PeripheralPerfusionIndex, BloodGlucose, NumberOfTimesFallen, ElectrodermalActivity, InhalerUsage, InsulinDelivery, BloodAlcoholContent, ForcedVitalCapacity, ForcedExpiratoryVolume1, PeakExpiratoryFlowRate.

Nutrition: DietaryFatTotal, DietaryFatPolyunsaturated, DietaryFatMonounsaturated, DietaryFatSaturated, DietaryCholesterol, DietarySodium, DietaryCarbohydrates, DietaryFiber, DietarySugar, DietaryEnergyConsumed, DietaryProtein, DietaryVitaminA, DietaryVitaminB6, DietaryVitaminB12, DietaryVitaminC, DietaryVitaminD, DietaryVitaminE, DietaryVitaminK, DietaryCalcium, DietaryIron, DietaryThiamin, DietaryRiboflavin, DietaryNiacin, DietaryFolate, DietaryBiotin, DietaryPantothenicAcid, DietaryPhosphorus, DietaryIodine, DietaryMagnesium, DietaryZinc, DietarySelenium, DietaryCopper, DietaryManganese, DietaryChromium, DietaryMolybdenum, DietaryChloride, DietaryPotassium, DietaryCaffeine, DietaryWater.  
- UVExposure

Sample Types include Quantity types plus:  
  
- Workout
- SleepAnalysis, AppleStandHour, CervicalMucusQuality, OvulationTestResult, MenstrualFlow, IntermenstrualBleeding, SexualActivity and MindfulSession.
- BloodPressure and CDA.

Object Types include all above plus:  
  
- activitySummary
- BiologicalSex
- BloodType
- DateOfBirth
- FitzpatrickSkinType
- WheelchairUse

Please enable HealthKit for the app entitlements for Xcode, add HealthKit framework and set NSHealthShareUsageDescription descriptor for info.plist.  
### Examples

Request authorization:

 Set Variable \[ $r ; Value: MBS ( "HealthKit.RequestAuthorizationToShareTypes"; ""; "BiologicalSex¶BloodType¶WheelchairUse¶DateOfBirth¶FitzpatrickSkinType¶StepCount" ; Get(FileName); "AuthorizeTrigger" ) \]   
If \[ $r ≠ "OK" \]   
 Show Custom Dialog \[ "Error" ; $r \]   
End If  
### See also

- [HealthKit.AuthorizationStatusForType](HealthKitAuthorizationStatusForType.md)

This function is free to use.

Created 25th April 2018 , last changed 13th January 2020

  
[HealthKit.FitzpatrickSkinType](HealthKitFitzpatrickSkinType.md) - [HealthKit.SampleQuery](HealthKitSampleQuery.md)

[HTML Version](HealthKitRequestAuthorizationToShareTypes.shtml)