SceneEvent
SceneEvent represents a scene connecting or disconnecting.
The sceneconnect and scenedisconnect events of application are this class, and scene is that scene. A scene is one instance of the app's UI; see UIWindowScene.
Inheritance: Event → SceneEvent
Constructor
Creates a SceneEvent. The runtime creates one itself when it fires the events below; app code can use it to build an event object and fire it with dispatchEvent() to try out a listener.
Instance properties
Also inherits the properties of Event; the most commonly used are type and target. The properties below are read-only; assigning to them throws TypeError.
| Property | Description |
|---|---|
scene read-only | The scene that connected or disconnected |
These properties live on the prototype, not on the event object itself: Object.keys(event) and { ...event } don't include them, so read them one by one. See Events with fields.
Events that use this class
| Object | Events |
|---|---|
application | sceneconnect, scenedisconnect |
It can't be canceled: cancelable is false, and preventDefault() has no effect.
Examples
application.addEventListener('sceneconnect', (e) => {
console.log(e instanceof SceneEvent, e.scene instanceof UIWindowScene);
const window = new UIWindow(e.scene);
window.rootViewController = new UIViewController();
window.makeKeyAndVisible();
});Effect: when the app launches and the scene connects, it prints true true, and the screen shows a blank page.
Corresponding iOS API
| ObjC | JS |
|---|---|
The scene parameter of scene:willConnectToSession:options: | event.scene of sceneconnect |
The scene parameter of sceneDidDisconnect: | event.scene of scenedisconnect |
See also
UIWindowScene: the sceneapplication: the object that fires these events