I am using the following code to record the heart rate from the internal watch sensor, which works fine! But when I stop the workout and want to start a new I am getting the error: workoutSession didFailWithError = Error Domain=com.apple.healthkit Code=3 "Stopped workout session cannot be restarted" UserInfo={NSLocalizedDescription=Stopped workout session cannot be restarted}
I think I have to clear in any kind the HKWorkoutSession *workoutSession and init it new but I don't know how?
Here is the code I am using:
@interface InterfaceController()
{
ExtensionDelegate *extensionDelegate;
/
HKHealthStore *healthStore;
HKWorkoutSession *workoutSession;
HKUnit *heartRateUnit;
HKQueryAnchor *anchor;
}
healthStore = [[HKHealthStore alloc] init];
workoutSession =[[ HKWorkoutSession alloc] initWithActivityType:HKWorkoutActivityTypeCrossTraining locationType:HKWorkoutSessionLocationTypeIndoor];
heartRateUnit = [HKUnit unitFromString:@"count/min"];
anchor = [HKQueryAnchor anchorFromValue:HKAnchoredObjectQueryNoAnchor];
workoutSession.delegate = self;
[healthStore startWorkoutSession:workoutSession];
How can I clear the workout session after stopping it for starting a new workout session:
[healthStore endWorkoutSession:workoutSession];
Not working:
workoutSession = nil;