HKHealthStore 没有添加正确的饮食能量值
HKHealthStore is not adding correct Diet Energy value passed
我正在尝试将用户的卡路里消耗添加到 Apple health kit 应用程序中。但是当它被添加到健康应用程序时,这个值被除以千。这是我添加到健康工具包的代码。
NSDictionary *calorieData = @{@"Unit": [HKUnit kilocalorieUnit], @"Identifier":HKQuantityTypeIdentifierDietaryEnergyConsumed};
HKQuantity *quantity = [HKQuantity quantityWithUnit:[HKUnit kilocalorieUnit] doubleValue:123];
NSDate *now = [NSDate date];
HKQuantityType *quantityType = [HKQuantityType quantityTypeForIdentifier:HKQuantityTypeIdentifierDietaryEnergyConsumed];
HKQuantitySample *sample = [HKQuantitySample quantitySampleWithType:quantityType quantity:quantity startDate:now endDate:now metadata:metaData];
[[self healthStore] saveObject:sample withCompletion:^(BOOL success, NSError *error) {
if (success)
NSLog(@"Added");
}];
我正在为健康包添加 123 千克卡路里。添加后它在健康应用程序中显示为 123 Cal。
当我从 HealthKit 中检索时,它是 123 kcal。
任何帮助将不胜感激!
大写“C”的卡路里相当于千卡。来自 Wikipedia:
The small calorie or gram calorie (symbol: cal) is the approximate
amount of energy needed to raise the temperature of one gram of water
by one degree Celsius at a pressure of one atmosphere.
The large calorie or kilogram calorie (symbol: Cal), also known as the food
calorie and similar names, is defined in terms of the kilogram
rather than the gram. It is equal to 1000 small calories, 1
kilocalorie (symbol: kcal).
我正在尝试将用户的卡路里消耗添加到 Apple health kit 应用程序中。但是当它被添加到健康应用程序时,这个值被除以千。这是我添加到健康工具包的代码。
NSDictionary *calorieData = @{@"Unit": [HKUnit kilocalorieUnit], @"Identifier":HKQuantityTypeIdentifierDietaryEnergyConsumed};
HKQuantity *quantity = [HKQuantity quantityWithUnit:[HKUnit kilocalorieUnit] doubleValue:123];
NSDate *now = [NSDate date];
HKQuantityType *quantityType = [HKQuantityType quantityTypeForIdentifier:HKQuantityTypeIdentifierDietaryEnergyConsumed];
HKQuantitySample *sample = [HKQuantitySample quantitySampleWithType:quantityType quantity:quantity startDate:now endDate:now metadata:metaData];
[[self healthStore] saveObject:sample withCompletion:^(BOOL success, NSError *error) {
if (success)
NSLog(@"Added");
}];
我正在为健康包添加 123 千克卡路里。添加后它在健康应用程序中显示为 123 Cal。 当我从 HealthKit 中检索时,它是 123 kcal。
任何帮助将不胜感激!
大写“C”的卡路里相当于千卡。来自 Wikipedia:
The small calorie or gram calorie (symbol: cal) is the approximate amount of energy needed to raise the temperature of one gram of water by one degree Celsius at a pressure of one atmosphere.
The large calorie or kilogram calorie (symbol: Cal), also known as the food calorie and similar names, is defined in terms of the kilogram rather than the gram. It is equal to 1000 small calories, 1 kilocalorie (symbol: kcal).