UISceneSession
UISceneSession represents a scene's session: the scene's persistent identity. The system may destroy a scene object and create it again; a session lives longer than the scene object. Use it to tell "this is a new scene" from "an earlier scene has connected again", and to store data belonging to this scene.
Read the session from the scene's session.
Inheritance: EventTarget → NSObject → UISceneSession
Constructor
Can't be created with new. new UISceneSession() throws TypeError: Illegal constructor: UISceneSession is created by the runtime, not by new.
Instance properties
| Property | Description |
|---|---|
role read-only | What the scene is for |
persistentIdentifier read-only | The unique identifier of this session |
userInfo | The app's own data, saved by the system |
None of these properties has a change event: the first two never change, and only the app's code changes userInfo.
Examples
js
application.addEventListener('sceneconnect', (e) => {
const session = e.scene.session;
console.log(session.role);
console.log(typeof session.persistentIdentifier);
});Result: Prints UIWindowSceneSessionRoleApplication and then string.
Corresponding iOS API
| ObjC | JS |
|---|---|
scene.session.persistentIdentifier | scene.session.persistentIdentifier |
scene.session.userInfo = @{ @"kind": @"mailDetail" } | scene.session.userInfo = { kind: 'mailDetail' } |