SwiftUI Button not fire the action inside the Dynamic island

426 Views Asked by At

I am attempting to trigger an action within a dynamic island by pressing a button, but the button is not functioning and no action is being executed.

dynamicIsland: { context in
  
    DynamicIsland {
        // Expanded UI goes here.  Compose the expanded UI through
        // various regions, like leading/trailing/center/bottom
        DynamicIslandExpandedRegion(.leading) {
            Text("Leading")
        }
        DynamicIslandExpandedRegion(.trailing) {
            Text("Trailing")
        }
        DynamicIslandExpandedRegion(.bottom) {
            Text("Bottom")
         ** Button {
            //Print here
            print("Pressed")
          } label: {
            Text("Press Me")**
          }.padding()

        }
    } compactLeading: {

I have tried testing in a new project, but I am still encountering the same problem with the button not firing any action.

1

There are 1 best solutions below

0
On

You can't use buttons in live activities the same way you do in an app. You need to use the App Intents Framework instead. Then you would add a button with the init(_:intent:) initializer.

From the documentation:

Buttons and toggles you add to your widgets and Live Activities use functionality that you expose to the system by adopting the App Intents framework. Before you add a button or toggle, make the app functionality available to the system using an app intent: