HKWorkoutSession不可用

时间:2016-10-21 15:09:49

标签: ios objective-c cocoa-touch health-kit

我在我的项目中使用HealthKit,我想在我的一个班级中声明HKWorkoutSession。我确实导入了<HealthKit/HealthKit.h>,我试图像这样声明:

@property (nonatomic) HKWorkoutSession *session;
<{1>}文件中的

。但是,我在这一行得到了一个错误:

  

&#39; HKWorkoutSessionDelegate&#39;不可用:iOS上不可用

我还尝试导入.h<HealthKit/HKWorkoutSession.h>,但都没有效果。

请注意<HealthKit/HKWorkout.h>中的所有其他类都可用(例如HealthKitHKHealthStore等)。我发现唯一不可用的是HKQueryHKWorkoutSession

2 个答案:

答案 0 :(得分:2)

HKWorkoutSession仅适用于watchOS。您需要避免在为iOS编译的代码中使用它。

答案 1 :(得分:2)

为什么需要通过手机访问HKWorkoutSession? watchOS使用该类来配置手表以准确测量用户的活动数据。

如果你正在尝试开始一个新的锻炼课程,你可以通过手机这样做:

let healthStore = HKHealthStore()

var workoutConfiguration = HKWorkoutConfiguration()
workoutConfiguration.activityType = .running
workoutConfiguration.locationType = .outdoor

healthStore.startWatchApp(with: workoutConfiguration) { (success, error) in
//Some code here
}