Nev*_*ore 5 healthkit apple-watch watchkit
我正在研究苹果手表应用程序,我正在使用HKworkoutsession访问心率数据样本.
在最新的watchos2 beta3发布错误"在活动的锻炼期间,屏幕关闭时不会生成新的心率样本." 是固定的.
我的问题是我怎么能把我的HKworkoutsession总是设置为"积极的锻炼课程",因此我可以随时获得心率样本.
谢谢瑞恩
以下代码是如何开始或停止锻炼课程.
let healthStore = HKHealthStore()
healthStore.startWorkoutSession(workoutSession) {
(result: Bool, error: NSError?) -> Void in
}
healthStore.stopWorkoutSession(workoutSession) {
(result: Bool, error: NSError?) -> Void in
}
Run Code Online (Sandbox Code Playgroud)
HKWorkoutSessionDelegate通知其会话状态.
protocol HKWorkoutSessionDelegate : NSObjectProtocol {
func workoutSession(workoutSession: HKWorkoutSession,
didChangeToState toState: HKWorkoutSessionState,
fromState: HKWorkoutSessionState, date: NSDate)
func workoutSession(workoutSession: HKWorkoutSession,
didFailWithError error: NSError)
}
Run Code Online (Sandbox Code Playgroud)
[编辑] 2015/08/31
ObjC版本
HKWorkoutSession *workoutSession = [[HKWorkoutSession alloc] initWithActivityType:HKWorkoutActivityTypeRunning locationType:HKWorkoutSessionLocationTypeOutdoor];
workoutSession.delegate = self;
HKHealthStore *healthStore = [HKHealthStore new];
[healthStore startWorkoutSession:workoutSession];
[healthStore stopWorkoutSession:workoutSession];
Run Code Online (Sandbox Code Playgroud)
HKWrokoutSessionDelegate
- (void)workoutSession:(HKWorkoutSession *)workoutSession
didChangeToState:(HKWorkoutSessionState)toState
fromState:(HKWorkoutSessionState)fromState
date:(NSDate *)date;
- (void)workoutSession:(HKWorkoutSession *)workoutSession didFailWithError:(NSError *)error;
Run Code Online (Sandbox Code Playgroud)
警告:方法名称的更改与最新版本有关,请观看OS 2 beta 5.
stopWorkoutSession已更改为endWorkoutSession.
| 归档时间: |
|
| 查看次数: |
3704 次 |
| 最近记录: |