区分iPhone应用程序崩溃和被杀死

区分iPhone应用程序崩溃和被杀死

本文介绍了区分iPhone应用程序崩溃和被杀死的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

限时删除!!

您好,我打算开发一个简单的iPhone游戏。我想要能够区分真正的崩溃和用户杀死应用程序(通过双击主屏幕并长时间点击它杀死它)。

Hello I am planning to develop a simple iPhone game. I would like to be able to distinguish between a genuine crash, and the user killing the app ( by double tapping home screen and long-clicking it to kill it) .

推荐答案

如果您的应用程序是通过多任务栏删除的,在后台和暂停时,当用户杀死它,它将不会收到通知。

If your app is in the background and suspended when the user kills it, it will receive no notification. This accounts for the majority of cases.

如果您的应用程式目前在后台运行(只有特定类别的应用程序可以那么它会收到 applicationWillTerminate

If your app is currently running in the background (there are only very specific categories of apps that can do that), then it receives applicationWillTerminate.

事实上,苹果很清楚,在进入背景之前保存任何相关数据。请查看(响应应用程序终止一章):

Indeed, Apple is very clear as to the fact that you should save any relevant data before entering the background. Have a look at this (chapter "Responding to Application Termination"):

编辑:

关于说对不起的事... ...

about the "saying sorry" thing...

你当然可以在下一个只需在 NSUserDefaults 中存储一个键,并在应用程序进入后台时删除它(我希望所有这些都听起来很熟悉,否则请查看UIApplicationDelegate协议)。

you can certainly do that on the next launch. simply store a key in NSUserDefaults and remove it when the app enters the background (I hope all this sounds familiar to you, otherwise look into the UIApplicationDelegate protocol).

当应用程序启动时,您检查密钥;如果它在那里,那么应用程序没有被用户关闭;如果应用程序不在那里,那么用户至少将应用程序移到后台,没有遇到任何突然终止...

when the app starts up, you check the key; if it is there, then the app was not closed by the user; if the app is not there, then the user at least moved the app to the background and did not experience any sudden termination...

这篇关于区分iPhone应用程序崩溃和被杀死的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

1403页,肝出来的..

09-07 01:29