Hi everyone. I'm trying to use the new ControlWidget API introduced on iOS 18 to open a sheet that contains a form when the user taps on the button on the control center.
This is my current code. It opens the app, but I haven't found how to do an action inside the app when the app is opened.
@available(iOS 18, *)
struct AddButtonWidgetControl: ControlWidget {
var body: some ControlWidgetConfiguration {
StaticControlConfiguration(kind: "com.example.myapp.ButtonWidget") {
ControlWidgetButton(action: LaunchAppIntent()) {
Label("Add a link", systemImage: "plus")
}
}
.displayName("Add a link")
.description("Creates a link.")
}
}
@available(iOS 18, *)
struct LaunchAppIntent: AppIntent {
static var title: LocalizedStringResource { "Launch app" }
static var openAppWhenRun: Bool = true
func perform() async throws -> some IntentResult {
return .result()
}
}