I'm trying to grab data from the Health App. Specifically data that the user did not enter in themselves. For instance, I have an iPhone 6+ that logs the amount of steps that I take. There is also an option to add the data manually; If you add the data manually, the health app marks the data as "user added".
Here's what's confusing me. Let's say I added a step count of 22. When I query the data using HKStatisticsQuery with a predicate of
HKQuery.predicateForObjectsWithMetadataKey(HKMetadataKeyWasUserEntered, allowedValues: [true])
HKQuery.predicateForObjectsWithMetadataKey(HKMetadataKeyWasUserEntered, allowedValues: [false])
Check for the below possible areas to fix it:
authorizationStatusForType:method available with HKHealthStore class.
My observations on wasUserEntered key is:
metadatadictionary along with
HKWasUserEnteredkey as TRUE automatically.
metadatadictionary with key
HKWasUserEnteredalong with value as either TRUE/FALSE. Otherwise, the
metadataproperty will contain
nilobject. Hence, Apple is not applying predicate(predicate contains metadata key) on the data which don't have metadata with it.
For debugging this metadata, try to print your
Apple's implementation on metadata Vs NSPredicate:
metadatadictionary to the respective health record.
metadatadictionary for his record of health data.
metadatafor a specific health record and
NSPredicatehave a constraint on
metadatathen, HealthKit completely omitting to validate such records.
It is advised to use
+ (instancetype)quantitySampleWithType:(HKQuantityType *)quantityType quantity:(HKQuantity *)quantity startDate:(NSDate *)startDate endDate:(NSDate *)endDate;
to add metadata.
metadatakey) should be applied on all the data irrespective of checking for
metadataexists or not.