Skip to content

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 ​

SceneEvent()

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.

PropertyDescription
scene read-onlyThe 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 ​

ObjectEvents
applicationsceneconnect, scenedisconnect

It can't be canceled: cancelable is false, and preventDefault() has no effect.

Examples ​

js
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 ​

ObjCJS
The scene parameter of scene:willConnectToSession:options:event.scene of sceneconnect
The scene parameter of sceneDidDisconnect:event.scene of scenedisconnect

See also ​