我正在通过选择加入(在 AppDelegate 中)来保存和恢复我的应用程序状态:
func application(application: UIApplication, shouldRestoreApplicationState coder: NSCoder) -> Bool {
return true
}
当我在应用程序后台运行后使用 Xcode 停止执行按钮终止应用程序时,这会起作用。
但是当我尝试终止设备上的后台应用程序(通过双击主页按钮并将应用程序向上滑动离开屏幕)时,应用程序状态在重新启动时不会恢复。
如何退出设备上的应用程序,以便它恢复其状态?还是现在只能使用 Xcode 对其进行测试?
最佳答案
我收到了 Apple 工程师的回复,他们确认这是正确的行为。他写道:
ISTR that removing the app from the multitasking UI specifically disables state restoration, on the grounds that the user only does this when there’s something wrong with the app and thus it’s better to start from a clean slate.
他说exit
函数可以用来测试保存后台状态:
Have you tried calling exit? It’s definitely not OK to do this in production code (see QA1561) but it’s fine to use while testing.
其他测试方法包括重启设备和更新应用。
关于ios - 在未连接 Xcode 的情况下在设备上测试应用程序状态保存/恢复,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40861720/