Some healthkit knowledge points by Wu xueying
HealthKitHKUnitHKUnit *g = [HKUnit gramUnit];HKUnit *dL = [HKUnit literUnitWithMetricPrefix:HKMetricPrefixDeci];HKUnit *gPerdL = [g unitDividedByUnit:dL];HKQuantityHKUnit *gramUnit = [HKUnit gramUnit];HKQuantity *grams = [HKQuantity quantityWithUnit:gramUnit doubleValue:20];double kg = [grams doubleValueForUnit:[HKUnit unitFromString:@"kg"]];BOOL kgCompatible = [grams isCompatibleWithUnit:[HKUnit unitFromString:@"kg"]];BOOL kCalCompatible = [grams isCompatibleWithUnit:[HKUnit kilocalorieUnit]];HKObjectNSString *identifier = HKQuantityTypeIdentifierBodyTemperature;HKQuantityType *tempType = [HKQuantity quantityWithUnit:[HKUnit degreeFahrenheitUnit] doubleValue:98.6];NSDictionary *meta = @{HKMetadataKeyBodyTemperatureSensoLocation:@(HKBodyTemperatureSensorLocationEar)};HKQuantitySample *temperatureSample = [HKQuantitySample QuantitySampleWithType:tempTypequantity:myTempstartDate:[NSDate date]endDate:[NSDate date]metadata:meta];HKHealthStoreself.store = [[HKHealthStore alloc] init];HKQuantitySample *mySample = [self newSample];[self.store saveObject:mySample withCompletion:^(BOOL success,NSError *error) {if (success) {}}];HKQuery --- PredicatesHKQuantity *weight = [NSPredicate predicateWithFormat:@"%K > %@",HKPredicateKeyPathQuantity,weight];HKAnchoredObjectQueryself.lastAnchor = 0;HKAnchoredObjectQuery *query;query = [[HKAnchoredObjectQuery alloc] initWithType:bloodSugarPredicate:nilanchor:self.lastAnchorlimit:HKObjectQueryNoLimitCompletionHandler:^(HKAnchoredObjectQuery *query,NSArray *results,NSUInteger newAnchor,NSError *error) {self.lastAnchor = newAnchor;NSLog(@"Results:%@",results);}];
Healthkit knowledge points