AppExtensionScene
An interface you use to provide a specific scene from your app extension’s UI.
Declaration
@MainActor @preconcurrency protocol AppExtensionSceneMentioned in
Overview
When your app extension provides custom UI, use this type to define a specific scene for that UI. An app extension can define multiple scene types in coordination with the host app. When the host app displays the app extension’s UI, it provides a unique string identifier for the scene it wants to display. The app extension responds by providing an instance of this type that contains that scene’s contents.
When defining a scene, provide the body of that scene using the PrimitiveAppExtensionScene type. This type contains the unique identifier of the scene and the content to display. The following code shows an implementation of a scene capable of displaying content you supply at initialization time using a closure. The scene’s body property repackages that content inside the PrimitiveAppExtensionScene structure. You can also use this type to accept a scene-specific XPC connection, which you might use to communicate custom data related to managing UI-related interactions.
struct MyScene<Content: View>: AppExtensionScene {
public init(content: @escaping () -> Content) {
self.content = content
}
private let content: () -> Content
public var body: some AppExtensionScene {
PrimitiveAppExtensionScene(id: “MyScene”) {
content()
} onConnection: { connection in
// TODO: Configure the XPC connection and return true
return false
}
}
}For more information about creating UI-based app extensions, see Including extension-based UI in your interface.