One Logo Pool Ball
AppIntents · IOS API REFERENCE

StartWorkoutIntent

protocol · iOS 16.0+ · SDK 27.1

protocol StartWorkoutIntent : InstanceDisplayRepresentable, SystemIntent

An App Intent for starting a workout. On Apple Watch Ultra, this intent registers a start workout action for the Action button. After installing your app, the user can select this action in Settings > Action Button by setting Action to Workout and App to your app. When implementing this intent, define the following: - A ``AppIntents/AppIntent/title`` property - A ``AppIntents/StartWorkoutIntent/workoutStyle-swift.property`` property - A list of ``AppIntents/StartWorkoutIntent/suggestedWorkouts`` - A ``AppIntents/InstanceDisplayRepresentable/displayRepresentation`` property - A ``AppIntents/AppIntent/perform()`` method ```swift struct MyStartWorkoutIntent: StartWorkoutIntent { // Define the intent's title. static var title: LocalizedStringResource = "Start Workout" // Define a list of start workout intents that appear below the First Press // settings when someone sets your app as the workout app in // Settings > Action Button. static var suggestedWorkouts: [MyStartWorkoutIntent] = [MyStartWorkoutIntent()] // Define a parameter that specifies the type of workout that this // intent starts. @Parameter(title: "Start Workout Entity") var workoutStyle: WorkoutEnum // Define an init method that sets the default workout type. init() { workoutStyle = .workout } // Set the display representation based on the current workout style. var displayRepresentation: DisplayRepresentation { WorkoutEnum.caseDisplayRepresentations[workoutStyle] ?? DisplayRepresentation(title: "Unknown") } // Launch your app when the system triggers this intent. static var openAppWhenRun: Bool { true } // Define the method that the system calls when it triggers this event. func perform() async throws -> some IntentResult { let workoutManager = MyWorkoutManager.shared await workoutManager.requestAuthorization() await workoutManager.startWorkout() return .result() } } ``` > Important: When defining the ``workoutStyle-swift.property`` property, ensure that it adopts either the ``AppIntents/AppEnum`` or ``AppIntents/AppEntity`` protocol. Declare this property using the ``AppIntents/AppIntent/Parameter`` property wrapper. For more information, see <doc:ActionButtonArticle>.

Members (0)

This type has no directly callable members in this snapshot. See the framework’s skipped declarations for unsupported APIs.

Skipped declarations

3 declarations were excluded from these bindings. Each reason comes from the generator or the iOS SDK compiler.

StartWorkoutIntent.openAppWhenRun

Static protocol requirements cannot be called through an instance.

StartWorkoutIntent.invalidateSuggestedWorkouts()

Static protocol requirements cannot be called through an instance.

StartWorkoutIntent.init(style:)

A protocol cannot be constructed directly.

All AppIntents types →