Skip to content

Enable State Restoration for iOS #647

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jan 21, 2021

Conversation

goderbauer
Copy link
Member

@goderbauer goderbauer commented Jan 15, 2021

Feature was implemented in flutter/engine#23495.

This enables it for the veggie seasons app according to the instructions to be published in flutter/flutter#73585.

To test state restoration on iOS:

  1. Open ios/Runner.xcworkspace/ in xcode.
  2. (iOS 14+ only): Switch to build in profile or release mode (launching an app from the home screen is not supported in debug mode), see screenshots in Document how to run profile/release from Xcode flutter#51673 (comment).
  3. Press the Play button in xcode to build and run the app.
  4. Create some in-memory state in the app on the phone, e.g. by navigating to a different screen.
  5. Background the app on the phone, e.g. by goign back to the home screen.
  6. Press the Stop button in xcode to terminate the app while running in the background.
  7. Open the app again on the phone (not via xcode), it will restart and restore its state.

@goderbauer
Copy link
Member Author

/cc @shihaohong

@goderbauer goderbauer requested a review from RedBrogdon January 15, 2021 18:06
@shihaohong
Copy link

shihaohong commented Jan 19, 2021

I tested the above workflow on the gallery app.

It worked on iOS simulators, but when I try it on an iOS 14.3 device, I get the following screen after on step 6:

I am not able to test on an iOS device <14 since I do not have a physical device on me, but I assume it should work there.

On the other hand, I also found the steps in this article seem to work on a physical iOS 14+ device. Basically, there's a bool on Info.plist you can set to kill an iOS app anytime it's backgrounded. This is similar to Android, but the important difference is that in iOS, this setting modifies an app's default behavior when it is backgrounded, whereas the Android testing steps modifies the target Android device's behavior for all apps. So, this runs the risk of the developer forgetting to flip the bool or removing it once they're done testing state restoration on iOS.

I think that your suggestion is still safer, but maybe we should recommend testing state restoration on iOS simulators instead of physical devices?

@goderbauer
Copy link
Member Author

goderbauer commented Jan 19, 2021

Alternatively, you could just run the app in profile or debug mode to test it.

I updated the instructions above to include that step.

@goderbauer goderbauer mentioned this pull request Jan 19, 2021
Copy link

@shihaohong shihaohong left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@goderbauer goderbauer merged commit a29af85 into flutter:master Jan 21, 2021
@goderbauer goderbauer deleted the restorationIos branch January 21, 2021 17:23
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants