iOS中的状态恢复 [英] state restoration in iOS

查看:409
本文介绍了iOS中的状态恢复的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在存储我的应用程序屏幕,因此当应用程序打开时,它将显示已存储的屏幕。该应用程序是基于导航的。

I am storing my application screen, so that when the application gets opened it will show the screen that was stored. The application is navigation based.

我已将Restoration ID分配给主故事板中的两个视图控制器。第一个控制器是导航控制器的根视图控制器。我还为导航控制器分配了Restoration Id。
现在问题是我运行应用程序时收到以下警告:

I have assigned the Restoration Ids to my two view controllers in main story board. The first controller is the root view controller of the navigation controller. I have also assigned Restoration Id to the navigation controller. Now the problem is when I run the application I am getting the following warning:


无法创建正在进行的恢复标记文件。

Unable to create restoration in progress marker file.

不确定还需要做什么。

推荐答案

之前我有同样的警告,并通过以下方式修复它。

I had the same warning before and fixed it by doing the followings.

我使用的是故事板。我的故事板只包括导航视图控制器和视图控制器(该导航视图控制器的根视图控制器)。在我的情况下,它是由以下两个原因之一引起的:

I was using storyboard. My storyboard only included a navigation view controller and a view controller (which was the root view controller of that navigation view controller). In my case, it was caused by either of the two reasons:

应用程序未正确设置状态保存
需要设置以下内容:

The application was not set up correctly for state preservation The followings need to be set:


  1. 在app delegate中,覆盖应用程序:willFinishLaunching。可以在该方法中简单地返回YES。

  1. In app delegate, override application:willFinishLaunching. One can simply return YES in that method.

对于每个视图控制器和视图(包括导航视图控制器和选项卡视图控制器),设置还原ID

For every view controllers and views (including the navigation view controllers and tab view controllers), set a restore ID

在app delegate中,选择加入 shouldSaveApplicationState shouldRestoreApplicationState

In app delegate, opt-in by overriding shouldSaveApplicationState and shouldRestoreApplicationState

如果仍然出现此警告,您可以查看在Xcode中运行应用的方式。我在Xcode模拟器中运行我的应用程序,并且必须遵循特定的序列来触发状态保存。

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.


  • 在Xcode模拟器中启动应用程序

  • 在Xcode模拟器中,单击主页按钮将应用程序放入后台。应该调用视图控制器的 encodeRestorableStateWithCoder 方法

  • 返回Xcode,点击停止 终止模拟的按钮

  • 在Xcode模拟器中,双击主页按钮,然后从应用程序切换器中删除应用程序

  • go回到Xcode,再次运行应用程序。

  • 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.

不应出现该警告。当我使用其他序列时,我看到出现了警告。当我使用Xcode在我的设备上调试我的应用程序时,我按照相同的顺序并没有看到警告。

That warning should not appear. When I used other sequences, I saw that warning appearing. When I debugged my app on my device using Xcode, I followed the same sequence and did not see the warning.

我认为该警告表示因为Xcode无法终止应用正确,状态恢复文件未正确保存到磁盘上。

I think that warning indicated that because Xcode could not terminate the app correctly, the state restoration file was not correctly saved onto the disk.

这篇关于iOS中的状态恢复的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆