ios - 在 iOS 上,如果没有 Apple Watch,如何收集锻炼时消耗的总能量?

标签 ios objective-c healthkit

将锻炼保存到 iOS 健康存储时,没有任何 Apple Watch,应用程序应如何计算总能量消耗?

Apple 的示例应用程序使用了 TotalEnergyBurned 的硬编码值,但表示现实世界的应用程序会根据传感器数据计算该值。

HKQuantity *energyBurned = [HKQuantity quantityWithUnit:[HKUnit kilocalorieUnit] doubleValue:425.0];

HKQuantity *distance = [HKQuantity quantityWithUnit:[HKUnit mileUnit] doubleValue:3.2];

HKWorkout *run = [HKWorkout workoutWithActivityType:HKWorkoutActivityTypeRunning
                                          startDate:start
                                            endDate:end
                                           duration:0
                                  totalEnergyBurned:energyBurned
                                      totalDistance:distance
                                           metadata:nil];

[self.healthStore saveObject:run withCompletion:^(BOOL success, NSError *error) {
}];

谢谢

最佳答案

除非您有 Apple Watch,否则 Apple 不会为您提供开箱即用的方法。

Strava 和 Nike Run 等应用程序根据以下因素计算消耗的卡路里:

  • 性别
  • 体重
  • 运行距离
  • 运行时长

您可以在 Google 上查找公式,甚至可以在 Stack Exchange 网络上的其他地方查找公式:https://fitness.stackexchange.com/questions/15608/energy-expenditure-calories-burned-equation-for-running进而链接到网络上的优质资源

关于ios - 在 iOS 上,如果没有 Apple Watch,如何收集锻炼时消耗的总能量?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58365702/

相关文章:

iOS 交互式 UILocalNotifications

ios - 检测是否手动输入了 HealthKit 事件

Swift HealthKit 触发心率示例

ios - 有什么方法可以同步 Map Vector(OpenGL 层)和 UIKit?

iphone - 如何在 UIScrollView 中同时拖动和移动某些东西并滚动

iphone - 用计数索引对数组进行排序

swift - 如何在远程服务器中持久保存 HKQueryAnchor

ios - Apple 拒绝 - 无法重现崩溃

iphone - NSXMLparser 错误代码 5

iPhone 开发盒?