2016-10-21 24 views
0

我在我的項目中使用HealthKit,我想在我的課程中聲明HKWorkoutSession。在.h文件HKWorkoutSession不可用

@property (nonatomic) HKWorkoutSession *session; 

:我做進口<HealthKit/HealthKit.h>,我想聲明它是這樣的。不過,我在這行錯誤:

「HKWorkoutSessionDelegate」是不可用:在iOS

我也嘗試導入<HealthKit/HKWorkoutSession.h><HealthKit/HKWorkout.h>不可用,但他們沒有工作。

請注意,HealthKit中的所有其他類都可用(如HKHealthStore,HKQuery等)。我發現唯一不可用的是HKWorkoutSessionHKWorkoutSessionDelegate

回答

1

HKWorkoutSession僅在watchOS上可用。您需要避免在爲iOS編譯的代碼中使用它。

0

爲什麼您需要從手機訪問HKWorkoutSession? WatchOS使用該類來配置手錶以準確測量用戶的活動數據。

如果你想開始一個新的健身課程,你可以從手機這樣做:

let healthStore = HKHealthStore() 

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

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