I tried creating a ControlWidget following this Apple document - https://developer.apple.com/documentation/widgetkit/creating-controls-to-perform-actions-across-the-system, but for some reason the Control is not showing while I am trying to add and on top of that the widget which we created prior to iOS18 is also not showing, while trying to add. Here is the gist of code :
struct WidgetLauncher{ static func main() { if #available(iOSApplicationExtension 18.0, *) { appWidgetsFor18.main() } else { appWidgets.main() }
struct apptWorkWidgets: WidgetBundle { var body: some Widget { WidgetPriorToiOS18() } } @available(iOSApplicationExtension 18.0, *) struct appWidgetsFor18: WidgetBundle { var body: some Widget { WidgetPriorToiOS18() PerformActionButton() //This from the apple's document. } }
@available(iOSApplicationExtension 18.0, *) struct PerformActionButton: ControlWidget { var body: some ControlWidgetConfiguration { StaticControlConfiguration( kind: "com.example.myApp.performActionButton" ) { ControlWidgetButton(action: PerformAction()) { Label("Perform Action", systemImage: "checkmark.circle") } } .displayName("Perform Action") .description("An example control that performs an action.") } }
struct PerformAction: AppIntent { static let title: LocalizedStringResource = "Perform action"
func perform() async throws -> some IntentResult {
// Code that performs the action...
return .result()
}
}