Contents

init(hostingDelegateClass:id:)

Creates a UISceneSessionActivationRequest customized to open a SwiftUI scene with the given identifier.

Declaration

init?<D>(hostingDelegateClass: D.Type, id: String) where D : UIHostingSceneDelegate

Parameters

  • hostingDelegateClass:

    A Class type that conforms to UIHostingSceneDelegate.

  • id:

    A string matching the id of one of the scenes declared in the sceneRepresentation’s content.

Discussion

The specified scene must be declared in the rootScene property of your hosting delegate class. The initializer will fail if no scene with the specified identifier is defined.

class HostingSceneDelegate: UIHostingSceneDelegate {
    static var rootScene: some Scene {
        WindowGroup(id: "swiftui-window") {
            ContentView()
        }
    }
}

if let requestWithID = UISceneSessionActivationRequest(
    hostingDelegateClass: HostingSceneDelegate.self,
    id: "swiftui-window"
) {
    UIApplication.shared.activateSceneSession(for: requestWithID)
}

When a UIScene is activated using this request object, its configuration is managed by SwiftUI. You will not see a call to your app delegate’s application(_:configurationForConnecting:options:) method.

An instance of the provided hosting delegate class will be created by SwiftUI and receive lifecycle callbacks for the associated scene.