问题
I get this warning in my iOS project: (iOS7, XCode 5 GM)
Warning: Unable to create restoration in progress marker file
I am working on a viewcontroller that turns all black when I get this warning on startup. Deleting the app and restarting XCode sometimes seems to help. I am returning NO on both
-(BOOL)application:(UIApplication *)application shouldRestoreApplicationState:
-(BOOL)application:(UIApplication *)application shouldSaveApplicationState:
Update1: I tested on iPhone4s. Same result. Warning and black screen on my view controller.
Update2: Answered my own question for the black screen. The warning just disappeared in latest iOS 7.0.x versions.
回答1:
Please make sure that you set a view controller as the initial view controller in your storyboard file. You will find this setting in the attributes inspector.
UPDATE
It sounds like you may not have added a restoration ID to the navigation controller itself but instead may have set the restoration IDs on child view controllers. If this is the case you should add the restoration id to the missing controller(s).
回答2:
I have not found why this message is printed in the console but I think it was some kind of bug in iOS. With the latest iOS 7 updates I do not get "Warning: Unable to create restoration in progress marker file" anymore.
The more interesting part is the black screen. It happens when you have a normal ViewController and a TableView inside. I had to create TWO outlets between view property of the ViewController and the base view (except the table view there is more views, that is the reason I had to use a generic view controller). There is one connection automatically with every ViewController so that was really strange. I assume it is again some kind of iOS bug.
回答3:
Adding the
UIViewControllerRestoration
solved it for me. If you click on the protocol reference it says :
// A class must implement this protocol if it is specified as the restoration class of a UIViewController.
@import UIKit;
@interface AppDelegate : UIResponder <UIApplicationDelegate, UIViewControllerRestoration>
@property (strong, nonatomic) UIWindow *window;
@end
In the docs it is written:
A restoration class implements the UIViewControllerRestoration protocol and is responsible for finding or creating a designated object at restore time. Here are some tips for when to use each one:
1) If the view controller is always loaded from your app’s main storyboard file at launch time, do not assign a restoration class. Instead, let your app delegate find the object or take advantage of UIKit’s support for implicitly finding restored objects.
2) For view controllers that are not loaded from your main storyboard file at launch time, assign a restoration class. The simplest option is to make each view controller its own restoration class.
So far I have understood it this way. Without the UIViewControllerRestoration protocol the appDelegate is not the restoration class (1). The warning is therefore written at the app start (restore time). The app delegate can not somehow find the object that needs to be assigned to the marker file. The problem is in the appDelegate. When the app delegate becomes the restorationClass it skips step 1) and goest to step 2). It seems that the appDelegate becomes the main restorationClass for all other views. The following method:
+ (UIViewController*) viewControllerWithRestorationIdentifierPath:(NSArray *)identifierComponents
coder:(NSCoder *)coder {}
is never called in my app and the restoration works without warinings or errors.
I would like to understand the problem and what is going on. I hope this helps you, and comments are welcome to clarify the problem. :)
来源:https://stackoverflow.com/questions/18932156/cryptic-warning-without-any-google-results-in-simulator