此警告消息出现在 iOS 8 和 9 设备以及模拟器上:
[Warning: Unable to create restoration in progress marker file]
它只在我第一次启动(首次安装)应用程序时显示一次。任何后续从 Xcode 启动此应用程序而不卸载它都不会显示此警告消息。
这对我的应用来说正常吗?这是我对我的代码所做的:
AppDelegate.swift:
import UIKit
@UIApplicationMain
class AppDelegate: UIResponder, UIApplicationDelegate {
var window: UIWindow?
func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject: AnyObject]?) -> Bool {
// Override point for customization after application launch.
return true
}
func application(application: UIApplication, willFinishLaunchingWithOptions launchOptions: [NSObject : AnyObject]?) -> Bool {
return true
}
func application(application: UIApplication, shouldSaveApplicationState coder:NSCoder) -> Bool{
return true;
}
func application(application: UIApplication, shouldRestoreApplicationState coder:NSCoder) -> Bool{
return true;
}
}
Restoration ID 纯粹在 Main.storyboard 中完成,因此 RestorationID 和 StoryboardID 相同。而且,只有顶级 View 具有与 StoryboardID 相同的 RestorationID。
在默认创建的选项卡式 View 应用程序中,我将以下内容应用于我的两个 Controller (第二个 Controller 改为命名为“SecondView”)
StoryboardID and RestorationID are the same
Top View has the RestorationID same as the StoryboardID
与此同时,如果我简单地将以下函数设置为 false 会发生什么:
func application(application: UIApplication, shouldSaveApplicationState coder:NSCoder) -> Bool{
return true;
}
func application(application: UIApplication, shouldRestoreApplicationState coder:NSCoder) -> Bool{
return true;
}
即使我的应用程序需要长时间处于锁定屏幕或后台,我的应用程序是否仍能正常工作?
最佳答案
仅供引用。这解决了我的问题:https://stackoverflow.com/a/20157399/49748
If this warning still occurred, you could check how you run your app in Xcode. I ran my app in Xcode simulator and had to follow a specific sequence to trigger state preservation.
launch the app in Xcode simulator
In Xcode simulator, click the "Home" button to put the app into the background. The
encodeRestorableStateWithCoder
method of the view controller should be calledgo back to Xcode, click the "stop" button to terminate the simulation
In Xcode simulator, double click the "Home" button and then remove the app from the app switcher and
go back to Xcode, run the app again.
关于Swift : [Warning: Unable to create restoration in progress marker file] during first launch 中的 iOS 8 和 9,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36111239/