ios - 在未连接 Xcode 的情况下在设备上测试应用程序状态保存/恢复

标签 ios testing device

我正在通过选择加入(在 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/

相关文章:

iOS - 收到内存警告

ios - Cordova inappbrowser状态栏iOS 7

angular - 如何等待TestCafe中的 Angular 执行?

php - 在 Yii2 中使用 codeception 进行功能测试时出现 404 错误

android - 当 Google Play 控制台设备目录中未显示特定设备品牌/型号时,如何排除它?

java - 基于单个 URL 请求对设备/用户进行身份验证

iOS 自动化测试题

ios - 使用 leftView 时在 UITextField 中移动文本

java - JMeter 与 Java Swing 应用程序

c - 开始对计算机以外的东西进行编程的最佳方式?