Contents

stateRestorationActivity(for:)

Returns a user activity object encapsulating the current state of the specified scene.

Declaration

optional func stateRestorationActivity(for scene: UIScene) -> NSUserActivity?

Parameters

  • scene:

    The scene whose state information is needed.

Discussion

Use this method to return an NSUserActivity object with information about your scene’s current state. Save enough information to be able to restore that state again after UIKit disconnects and then reconnects the scene. User activity objects are a mechanism to record what the user is doing, so you don’t need to manually persist the state of your scene’s UI.

After calling this method, and before archiving the NSUserActivity object and saving it to disk, UIKit lets you add state information as follows:

When reconnecting the scene and restoring state, the user activity provided by this method will be provided in the stateRestorationActivity property of UISceneSession.

See Also

Saving the state of the scene