Application: scenes property
The scenes property is the currently connected scenes.
Value
A read-only array of UIWindowScene.
- Read-only. Assigning to it throws
TypeError. - An empty array while the top level of
main.jsruns: the system creates scenes only after the script finishes. So don't readapplication.scenes[0]at the top level; you'll getundefined. - Scenes the system uses internally aren't included, such as the scene the system creates when the keyboard appears.
- The same scene is the same JS object on every read, so it can be compared with
===. In thesceneconnectcallback,e.sceneand the first element here are the same object. - Fires
sceneconnectandscenedisconnectwhen it changes.
Examples
js
console.log(application.scenes.length);
application.addEventListener('sceneconnect', (e) => {
console.log(application.scenes[0] === e.scene);
});Result: the first line prints 0. After the scene connects, the callback prints true.
Corresponding iOS API
UIApplication.connectedScenes. Natively it's a set; here it's an array.