我正在使用以下代码停止锻炼:
[healthStore endWorkoutSession:workoutSession];
该行触发:
-(void)workoutSession:(nonnull HKWorkoutSession *)workoutSession didChangeToState:(HKWorkoutSessionState)toState fromState:(HKWorkoutSessionState)fromState date:(nonnull NSDate *)date
“ toState”正变成“ HKWorkoutSessionStateEnded”
到目前为止,一切都很好。但正如Apple Developer Docu所写:HKWorkoutSessionStateEnded: 手表无法再在后台运行。它的传感器恢复正常,并且不再生成锻炼数据。您无法重新开始或重复使用锻炼课程。
但是Apple Watch传感器仍然呈绿色。我必须停止其他事情吗?
这是我用来设置healthStore的代码:
-(void)initHealthStore
{
healthStore = [[HKHealthStore alloc] init];
HKWorkoutConfiguration *configuration = [HKWorkoutConfiguration new]; // start workout
configuration.activityType = HKWorkoutActivityTypeCrossTraining;
configuration.locationType = HKWorkoutSessionLocationTypeIndoor;
workoutSession = [[HKWorkoutSession alloc] initWithConfiguration:configuration error:nil];
NSInteger wristLocation;
wristLocation = [[WKInterfaceDevice currentDevice] wristLocation];
heartRateUnit = [HKUnit unitFromString:@"count/min"];
anchor = [HKQueryAnchor anchorFromValue:HKAnchoredObjectQueryNoAnchor];
workoutSession.delegate = self;
}