在未连接 Xcode 的设备上测试应用程序状态 Saving/Restoration
Testing App State Saving/Restoration on Device without Xcode Connected
我正在通过选择加入(在 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.
其他测试方法包括重启设备和更新应用程序。
我正在通过选择加入(在 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.
其他测试方法包括重启设备和更新应用程序。