Home > Net >  How to read the physical Action button of the Apple Watch Ultra?
How to read the physical Action button of the Apple Watch Ultra?

Time:09-09

Is there a way to read the Action button of the Apple Watch Ultra in SwiftUI?

enter image description here

You can read the Digital Crown like in the example below, but I've found nothing similar for the Action button?

struct DigitalCrown: View {
    @State private var crownValue = 0.0

    var body: some View {
        Text("Received Value:\(crownValue, specifier: "%.1f")")
            .focusable()
            .digitalCrownRotation($crownValue)
    }
}

CodePudding user response:

I haven't found how to designate an action but there is a UI test.

XCUIDevice.current.press(.action)

https://developer.apple.com/documentation/xcode-release-notes/xcode-14-release-notes

From the wording I am guessing it might be a "Shortcut"

CodePudding user response:

The Apple Watch Ultra’s Action Button is powered by new App Intents APIs. You will be able to build your own apps to integrate with it, like a hockey app that uses the button to record goals. And for users, the button can kick off any Shortcut you want.

To use this, make an Intent that conforms to the StarWorkoutIntent protocol: https://developer.apple.com/documentation/appintents/startworkoutintent

These APIs are meant for Workout apps, so to put this new button in a mode where it’s controlling your app, you’ll need to at least start with a StartWorkoutIntent.

Once you’re done with that, you can create an AppIntent result with an actionButtonIntent to set the next thing the button will do, to any other intent. Or, if you’re changing the button’s behavior based on something that happened in your app’s UI, you can use donations to do so.

https://twitter.com/mgorbach/status/1567570300820144131

  • Related