Swift : [Warning: Unable to create restoration in progress marker file] during first launch 中的 iOS 8 和 9

标签 ios swift state

此警告消息出现在 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 called

  • go 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/

相关文章:

ios - 防止弹出框显示过度呈现的 View

javascript - 如何在react-native或reactjs中维护react usestate中的先前数据和当前数据?

ios - 使用 AVAudioEngine 实现立体声麦克风直通?

ios - iOS-UITableViewCell中的UIButton的长按手势识别器

ios - 使用 UITextView 在 NSAttributedString 中自动调整图像大小

ios - UICollectionView Header - 计算复杂 View 的大小

ios - 当 ScrollView subview 不在屏幕上时手势识别器不工作

swift - 将 View Controller 推到 NavigationController 后,导航标题未显示在中心

Flutter:全局保存列表的方法是什么,以便在浏览我的应用程序后保持状态?

android - 媒体播放器正在播放抛出非法状态android