c++ - iOS 处理强制应用程序退出的正确方法是什么

标签 c++ ios objective-c

当应用程序被强制退出时,iOS 是否会发出某种类型的通知?

强行是指当应用程序处于事件状态时点击主页按钮,然后将其从多任务菜单中删除。

我希望能够检测到强制退出,以优雅地处理所有事情。

我们的一款游戏遇到了这样的问题,我们的发行商希望我们处理这个问题。 这不是标准的 Cocoa 应用程序,这是从 PC 移植的游戏,主要用 C++ 编写。

这只发生在第二代 iPad Mini 上,当应用程序被强制退出时,它会在下次启动时崩溃。 在其他设备上,当应用程序被激活时,它将正确加载并继续正确的场景加载顺序。

iPad mini 2nd gen 在开发方面与其他设备有什么不同吗?

崩溃日志显示应用程序在强制退出后立即崩溃,好吧......

- (void)applicationWillTerminate:(UIApplication *)application 并不是很有用,它不会检测强制应用程序退出。

最佳答案

我们的想法是,无论终止是由操作系统还是由用户启动,您的应用都应该以相同的方式处理终止。我们鼓励您保存应用程序的状态并在下次启动时重新加载。当您的应用程序被发送到后台时保存状态可能是个好主意,因为根据下面的第二段,系统终止您的应用程序时并不总是调用 applicationWillTerminate

根据documentation

This method lets your app know that it is about to be terminated and purged from memory entirely. You should use this method to perform any final clean-up tasks for your app, such as freeing shared resources, saving user data, and invalidating timers.

还有

For apps that do not support background execution or are linked against iOS 3.x or earlier, this method is always called when the user quits the app. For apps that support background execution, this method is generally not called when the user quits the app because the app simply moves to the background in that case. However, this method may be called in situations where the app is running in the background (not suspended) and the system needs to terminate it for some reason.

关于c++ - iOS 处理强制应用程序退出的正确方法是什么,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25055398/

相关文章:

c++ - 内存中的继承保护成员变量拷贝

ios - 将 OpenSSL 与 PJSIP 集成构建错误

php - 输入类型 "file"在 iPad 上不起作用

objective-c - 我可以向 Objective-C 枚举添加方法吗?

iphone - dateByAddingTimeInterval 在 IOS 应用程序开发中没有给出预期的结果

c++ - 如何从派生类实例化基类中的数组?

c++ - 为什么右值引用可以绑定(bind)到函数?

java - 在 c++/java 中创建 sql 查询?

ios - UILabel 设置为隐藏时不隐藏

objective-c - UILabel [__NSCFString 集] : unrecognized selector sent to instance crash