I want to get which button in AccessoryWidgetGroup was pressed in the Watch App, but I can't.
When I use Button(_:intent:), it works in Smart Stack, but it doesn't work in Complication Widget.
Using widgetURL(_:) always gets the URL of the first button.
Below is a snippet of the code I tried. All codes can be found here.
struct MyWatchWidgetEntryView : View {
var entry: Provider.Entry
var body: some View {
AccessoryWidgetGroup("Widget Group") {
MyWatchWidgetEntryButton(intent: .init(id: "001", imageName: "star.fill"))
MyWatchWidgetEntryButton(intent: .init(id: "002", imageName: "heart.fill"))
MyWatchWidgetEntryButton(intent: .init(id: "003", imageName: "leaf.fill"))
}
}
}
//Button View
private struct MyWatchWidgetEntryButton: View {
@Environment(\.showsWidgetContainerBackground) var showsWidgetContainerBackground
let intent: MyAppIntent
var body: some View {
Button(intent: intent) {
ZStack {
if showsWidgetContainerBackground {
Color.black
} else {
AccessoryWidgetBackground()
}
VStack {
Image(systemName: intent.imageName)
.font(.headline)
Text(intent.id)
.font(.system(size: 10, weight: .bold))
}
}
}
.buttonStyle(.plain)
.widgetURL(URL(string: "widget://" + intent.id))
}
}
Does anyone know how to do this?
Thank you.