PolarTrainingSessionApi
public protocol PolarTrainingSessionApi
Protocol defining methods to access training session data.
-
Get training session references for a given period. If fromDate and toDate are not given this method will return all training session references in the device. Otherwise returns list of training session references from the specified closed or half-open date interval.
Requires
Requires SDK feature(s):PolarBleSdkFeature.feature_polar_training_dataThrows
SeePolarErrorsfor possible errors.Declaration
Swift
func getTrainingSessionReferences( identifier: String, fromDate: Date?, toDate: Date? ) async throws -> [PolarTrainingSessionReference]Parameters
identifierThe Polar device ID or BT address.
fromDateThe starting date of the period to retrieve training session references from. Optional.
toDateThe ending date of the period to retrieve training session references from. Optional.
Return Value
An array of
PolarTrainingSessionReferenceobjects for the specified period. -
Get a specific training session using a reference.
Requires
Requires SDK feature(s):PolarBleSdkFeature.feature_polar_training_dataThrows
SeePolarErrorsfor possible errors.Declaration
Swift
func getTrainingSession( identifier: String, trainingSessionReference: PolarTrainingSessionReference ) async throws -> PolarTrainingSessionParameters
identifierThe Polar device ID or BT address.
trainingSessionReferenceThe reference to the training session to retrieve.
Return Value
PolarTrainingSessioncontaining the session data. -
Get a specific training session using a reference with progress updates.
Requires
Requires SDK feature(s):PolarBleSdkFeature.feature_polar_training_dataThrows
SeePolarErrorsfor possible errors.Declaration
Swift
func getTrainingSessionWithProgress( identifier: String, trainingSessionReference: PolarTrainingSessionReference, progressHandler: @escaping (PolarTrainingSessionProgress) -> Void ) async throws -> PolarTrainingSessionParameters
identifierThe Polar device ID or BT address.
trainingSessionReferenceThe reference to the training session to retrieve.
progressHandlerA closure called with
PolarTrainingSessionProgressas the session data is being fetched.Return Value
PolarTrainingSessioncontaining the complete session data. -
deleteTrainingSession(identifier:Asynchronousreference: ) Api for removing single training session from a Polar device. You can get a list of training sessions with
getTrainingSessionReferencesAPI.Requires
Requires SDK feature(s):PolarBleSdkFeature.feature_polar_training_dataThrows
SeePolarErrorsfor possible errors invoked.Declaration
Swift
func deleteTrainingSession(identifier: String, reference: PolarTrainingSessionReference) async throwsParameters
identifierThe Polar device ID or BT address.
referencePolarTrainingSessionReference with path in device to the training session to be removed.
-
startExercise(identifier:Asynchronousprofile: ) Start an exercise session on the device.
Requires
Requires SDK feature(s):PolarBleSdkFeature.feature_polar_training_dataThrows
PolarErrors.invalidArgumentifprofileis.unknown, or an error if the operation fails or the device does not support the requested sport.Declaration
Swift
func startExercise(identifier: String, profile: PolarExerciseSession.SportProfile) async throwsParameters
identifierThe Polar device ID or BT address.
profileSport profile to use for the exercise session.
-
startExercise(identifier:Default implementation, asynchronoussportId: ) Start an exercise using a numeric Polar sport ecosystem identifier, including sports not listed in
PolarExerciseSession.SportProfile.Requires
Requires SDK feature(s):PolarBleSdkFeature.feature_polar_training_dataThrows
PolarErrors.invalidArgumentifsportIdis zero or greater thanInt64.max; or an error if the device rejects the sport or the operation fails.Default Implementation
Compatibility implementation for conformers that do not implement numeric sport IDs. Only known
SportProfilevalues are supported by this default; SDK implementations may override it to support additional installed sport IDs.Declaration
Swift
func startExercise(identifier: String, sportId: UInt64) async throwsParameters
identifierThe Polar device ID or BT address.
sportIdPositive sport identifier no greater than
Int64.max. -
pauseExercise(identifier:Asynchronous) Pause an ongoing exercise session.
Requires
Requires SDK feature(s):PolarBleSdkFeature.feature_polar_training_dataThrows
SeePolarErrorsfor possible errors invoked.Declaration
Swift
func pauseExercise(identifier: String) async throwsParameters
identifierThe Polar device ID or BT address.
-
resumeExercise(identifier:Asynchronous) Resume a paused exercise session.
Requires
Requires SDK feature(s):PolarBleSdkFeature.feature_polar_training_dataThrows
SeePolarErrorsfor possible errors invoked.Declaration
Swift
func resumeExercise(identifier: String) async throwsParameters
identifierThe Polar device ID or BT address.
-
stopExercise(identifier:Asynchronoussave: ) Stop the current exercise session.
Requires
Requires SDK feature(s):PolarBleSdkFeature.feature_polar_training_dataThrows
SeePolarErrorsfor possible errors invoked.Declaration
Swift
func stopExercise(identifier: String, save: Bool) async throwsParameters
identifierThe Polar device ID or BT address.
saveWhether to save the stopped exercise on the device. Defaults to
true. Passfalseto discard the session without persisting it, which avoids the need for a subsequent stop → list → delete sequence. -
getExerciseStatus(identifier:Asynchronous) Get the current exercise session status from the device.
Requires
Requires SDK feature(s):PolarBleSdkFeature.feature_polar_training_dataThrows
SeePolarErrorsfor possible errors invoked.Declaration
Swift
func getExerciseStatus(identifier: String) async throws -> PolarExerciseSession.ExerciseInfoParameters
identifierThe Polar device ID or BT address.
Return Value
The current
PolarExerciseSession.ExerciseInfofor the device. -
Observe exercise session status notifications from the device.
Requires
Requires SDK feature(s):PolarBleSdkFeature.feature_polar_training_dataDeclaration
Swift
func observeExerciseStatus(identifier: String) -> AsyncThrowingStream<PolarExerciseSession.ExerciseInfo, Error>Parameters
identifierThe Polar device ID or BT address.
Return Value
AsyncThrowingStreamemittingPolarExerciseSession.ExerciseInfowhenever the session status changes. -
startExercise(identifier:Extension method, asynchronous) Start an exercise with the default sport,
.otherOutdoor.Requires
Requires SDK feature(s):PolarBleSdkFeature.feature_polar_training_dataThrows
SeePolarErrorsfor possible errors.Declaration
Swift
func startExercise(identifier: String) async throws -
stopExercise(identifier:Extension method, asynchronous) Convenience overload that saves the exercise on the device (default behaviour).
Declaration
Swift
func stopExercise(identifier: String) async throws
View on GitHub