你的位置:首页 > 软件开发 > 操作系统 > iOS Programming State Restoration 状态存储

iOS Programming State Restoration 状态存储

发布时间:2015-05-27 00:00:37
iOS Programming State Restoration 状态存储If iOS ever needs more memory and your application is in the background, Apple might kill it to r ...

iOS Programming State Restoration 状态存储

iOS Programming State Restoration 状态存储

If iOS ever needs more memory and your application is in the background, Apple might kill it to return memory to the system.

如果iOS 需要更多的memory,你的应用在后台,apple 可能杀死它来得到更多的内存给系统。

This should be transparent to your users; they should always return to the last spot they were within the application.

这可能是对你来说是透明的,他们总是返回他们在应用的最后一个spot。

To achieve this transparency, you must adopt state restoration within your application. State restoration works a lot like another technology you have used to persist data – archiving.

为了得到这种transparency,你必须采用state restoration 在你的应用中。state restoration 工作起来像你用过persist data 的技术-archiving .

When the application is suspended, a snapshot of the view controller hierarchy is saved.

当应用被挂起时,一个view controller hierarchy 的snapshot 被存储。

If the application was killed before the user opens it again, its state will be restored upon launch.

如果应用在用户再次打开之前被杀掉了,它的状态就会被存储到launch。

If the application has not been killed, then everything is still in memory and you have no need to restore any state.)

如果应用还没有被杀掉,所有的东西都在内存中,你不必要存储任何状态。

If an application does not implement state restoration, the user will briefly see the previous application state, but then the screen will change to its fresh-launch state.

如果一个应用没有实现state restoration ,那么用户将短暂的看到之前的应用程序状态,但是然后屏幕将改变到它的新启动的状态。

1 How State Restoration Works

A running app can be thought of as a tree of view controllers and views, with the root view controller as the root of the tree.

一个running app 能被认为是一个view controller ,view 和root view controller 作为树的根的树。

For example, the interface of your HypnoNerd app can be thought of as a tree like this:

iOS Programming State Restoration 状态存储

If you opt-in to state restoration, before your app is terminated, the system walks this tree asking each node, "What is your name?", "What is your class?", and "Do you have any data you want me to hold on to?" While the app is dead, this description of the tree is stored on the file system.

当你选择的状态存储,在你的app被终结之前,system 遍历这个树,询问每个节点,"你的名字是什么","你的类是什么""你是否有任何数据想让我保持"。当app is dead,tree 的表述被存储到文件系统中。

A node's name, actually called the restoration identifier, is typically the object's class name. The restoration class is typically the class of the object. The data holds the state of the object. For example, the data for a tab view controller includes which tab is currently selected.

一个node的名字,确切的称为对象类的名字,restoration class 一般是这个对象的类。数据保持了这个对象的状态。例如一个tab view controller的数据包括现在选择了哪个tab。

When the app is restarted, the system tries to recreate the tree of view controllers and views from that saved description.

当app 被重新开始时,系统视图recreate 这个view controllers 和view的tree从那个被存储的表述。

For each node:

(1)The system asks the restoration class to create a new view controller for that node.

系统询问restoration 类来创建一个新的view  controller 为那个节点。

 

海外公司注册、海外银行开户、跨境平台代入驻、VAT、EPR等知识和在线办理:https://www.xlkjsw.com

原标题:iOS Programming State Restoration 状态存储

关键词:IOS

IOS
*特别声明:以上内容来自于网络收集,著作权属原作者所有,如有侵权,请联系我们: admin#shaoqun.com (#换成@)。