Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

iOS state restoration animation bug

I just wanted to implement the iOS State-Restoration APIs in one of my Apps. After finally getting it to work, I discovered that a ViewController that I present modally gets restored using an animation, which is not what I want. I would expect my app to just be in the state I left it, but not having the user to see hot he got there.

So I went ahead and downloaded Apple Sample Code on that: https://developer.apple.com/library/ios/samplecode/StateRestore/Introduction/Intro.html and wanted to see if it happens there as well. And it turns out that it does.

Further there is a warning in the Logs:

Unbalanced calls to begin/end appearance transitions for <UINavigationController: 0x7b0512b0>.

Can you tell me if I and obviously Apples Sample Code are doing something wrong, or if it's a bug in iOS?

Btw. I was testing on iOS8

Thanks for any help, Georg

like image 433
Georg Avatar asked Oct 20 '14 08:10

Georg


2 Answers

The following solution comes directly from Apple.

In your app delegate, you should be implementing application:willFinishLaunchingWithOptions: (instead of or in addition to didFinishLaunching). In your implementation, probably as the last line just before returning true (or YES if this is Objective-C), insert this line:

self.window?.makeKeyAndVisible()

Or, if this is Objective-C:

[self.window makeKeyAndVisible];

It turns out that this was always needed, but the documentation has never been clear about it.

like image 84
matt Avatar answered Sep 20 '22 19:09

matt


From documentation: Preserving Your App’s Visual Appearance Across Launches

See the 3rd item from the checklist below.

Checklist for Implementing State Preservation and Restoration

Supporting state preservation and restoration requires modifying your app delegate and view controller objects to encode and decode the state information. If your app has any custom views that also have preservable state information, you need to modify those objects too.

When adding state preservation and restoration to your code, use the following list to remind you of the code you need to write.

  • (Required) Implement the application:shouldSaveApplicationState: and application:shouldRestoreApplicationState: methods in your app delegate; see Enabling State Preservation and Restoration in Your App.
  • (Required) Assign restoration identifiers to each view controller you want to preserve by assigning a non empty string to their
    restorationIdentifier property; see Marking Your View Controllers for Preservation.

    If you want to save the state of specific views too, assign non empty strings to their restorationIdentifier properties; see Preserving the State of Your Views.

  • (Required) Show your app’s window from the application:willFinishLaunchingWithOptions: method of your app delegate. The state restoration machinery needs the window so that it can restore scroll positions and other relevant bits of your app’s interface.

  • Assign restoration classes to the appropriate view controllers. (If
    you do not do this, your app delegate is asked to provide the
    corresponding view controller at restore time.) See Restoring Your
    View Controllers at Launch Time.

  • (Recommended) Encode and decode the state of your views and view controllers using the encodeRestorableStateWithCoder: and decodeRestorableStateWithCoder: methods of those objects; see Encoding and Decoding Your View Controller’s State.
  • Encode and decode any version information or additional state information for your app using the application:willEncodeRestorableStateWithCoder: and application:didDecodeRestorableStateWithCoder: methods of your app delegate; see Preserving Your App’s High-Level State.

  • Objects that act as data sources for table views and collection views should implement the UIDataSourceModelAssociation protocol. Although not required, this protocol helps preserve the selected and visible items in those types of views. See Implementing Preservation-Friendly Data Sources.

like image 33
A. Poltoratskyi Avatar answered Sep 20 '22 19:09

A. Poltoratskyi