I am trying to read Personal Details (Blood group, Age, Gender) of Healthkit
but unable to request for that.
As per Apple Doc here:
HealthKit provides five characteristic types: biological sex, blood
type, birthdate, Fitzpatrick skin type, and wheelchair use. These
types are used only when asking for permission to read data from the
HealthKit store.
But i can’t make add HKCharacteristicType
in authorisation request.
I have run Apple Sample Project which requests for:
HKQuantityTypeIdentifier.stepCount.rawValue,
HKQuantityTypeIdentifier.distanceWalkingRunning.rawValue,
HKQuantityTypeIdentifier.sixMinuteWalkTestDistance.rawValue
But when I add
HKCharacteristicTypeIdentifier.bloodType.rawValue
HKCharacteristicTypeIdentifier.dateOfBirth.rawValue
The permission screen does not asks for DOB and Blood Type. See Image:
Configuration: Simulator iOS 15.4 and Xcode 13.3
Anyone knows that if we can access Personal Data of HealthKit or not. Please help me out.
2
Answers
You can only request read authorization for the HKCharacteristicTypes, not share authorization. Update your code to add these 2 data types only to the
readDataTypes
variable. Right now you are requesting both read & share for the characteristic types, which is why they are not appearing on the authorization sheet.This is happening because
bloodType
anddateOfBirth
are of typeHKCharacteristicType
when you call this, the
compactMap
operation will not include your typescheck
getSampleType
:your types won’t fall into any of these
if let
, so this function will returnnil
. You must change the code so you are able to useHKCharacteristicTypeIdentifier
as well.EDIT: An easy way to do this is changing the
readDataTypes
inHealthData
class to: