Open an specific view or sheet of the app from a control widget button

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()
    }
}

I think you need to explore “deep linking” solutions in your app. That’s the concept of entering the application at a screen lower than the first view.

I chose to solve it with a singleton but I think there’s a new @Dependency you can use these days.

widgetURL is the appropriate API for this.

Rico

WWDR - DTS - Software Engineer

Open an specific view or sheet of the app from a control widget button
 
 
Q