gpt4 book ai didi

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

转载 作者:塔克拉玛干 更新时间:2023-11-02 21:21:53 25 4
gpt4 key购买 nike

当应用程序被强制退出时,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/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com