Upgrade to Pro — share decks privately, control downloads, hide ads and more …

App State Restoration - Swift Bangalore #9

Eeb061c8b2816b771920da1b3e7904a3?s=47 Swift India
September 22, 2018

App State Restoration - Swift Bangalore #9


Swift India

September 22, 2018


  1. App State Restoration G. Abhisek iOS Engineer at OLA

  2. What are we gonna discuss? • What is State Restoration?

    • How does it help us? • How does it work internally? • How to integrate?
  3. What is App State Restoration? • Restore Behaviour and Appearance

    • Restore applications Semantic State
  4. What are we looking at?

  5. How does it help us? Only the strongest will survive

  6. Let us INTEGRATE …. !! • App Delegate • View

    Controllers • Save Data & Restore Data
  7. App Delegate • Enable State Restoration

  8. View Controllers • Provide with Restoration Identifier • Confirm to

    UIStateRestoring Protocol • Provide a Restoration Class (Optional) • Confirm to UIViewControllerRestoration Protocol (Optional) • Encode and Decode relevant Data
  9. • If RestorationIdentifier is not set, UIKit skips restoration for

    the view controller & subsequent controllers in hierarchy • Storyboard handles providing restoration class and reference to controller for restoration • If implemented without storyboard, provide restoration id, restoration class and controllers instance.
  10. UIStateRestoring Protocol

  11. UIViewControllerRestoration Protocol

  12. What to save? What not to save? • Data necessary

    to recreate the view controller • Primary key of records • UI states e.g. Slider value, Button Selection • Its not user defaults nor data • Saved state can be lost • If data is a preference, don’t store it in state restoration archive • Don’t convert to data and encode
  13. Control Flow App Launches Load initial UI First App initialisation

    Does your app supports state restoration ? Get the ViewControllers Decode saved objects Finish App restoration Finish App Initialisation Run App NO YES UIKit appDelegate: applicationWillFinishLaunching: appDelegate: shouldRestoreApplicationState: viewController: withRestorationIdentifierPath viewController: decodeRestorableState appDelegate: didDecodeRestorableState
  14. Testing State Restoration • RestorationArchiveTool • StateRestorationDebugLogging.mobileconfig • StateRestorationDeveloperMode.mobileconfig

  15. What we discussed? • What is State Restoration? • What

    are its benefits? • How to integrate within App? • Do’s and Don’ts • Control Flow
  16. Thanks