applicationWillTerminate何时被调用,何时不被调用 [英] applicationWillTerminate when is it called and when not

查看:252
本文介绍了applicationWillTerminate何时被调用,何时不被调用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

您好我已经阅读了几个关于applicationWillTerminate被调用而没有被调用的问题。

Hi I have read several questions on SO about applicationWillTerminate getting called and not getting called.

我想总结一下我的理解,因为有几个帖子说的不同。

I wanted to summarize what I understood as there are several posts that speak differently.


  1. 对于IOS(没有多任务处理),当按下主页按钮时,它总是被调用。

  1. For IOS (without multitasking) it is called always when home button is pressed.

适用于IOS 4及以上

For IOS 4 and above

a。当按下主页按钮时(当应用程序移动到后台时)

a. it is not called when pressing home button (as the app moves to background)

b。从多任务停靠平台关闭应用程序时调用它,如果应用程序在info.plist中有一个突然终止标志禁用,则不会调用它。 (我设置应用程序应该得到应用程序死亡事件,然后在从多任务停靠点关闭应用程序时终止功能未被调用)

b. it is called when closing the app from the multi tasking dock and if the app has a sudden terminate flag in info.plist disabled else it is not called. ( I set the "Application should get App Died events" and even then on closing the app from the multitasking dock the terminate function did not get called)

基于此我有几个问题

将应用程序设置为应该是一个好习惯吗? App Died事件标志? (我设置了应该应用程序应用程序死亡事件,甚至在从多任务停靠点关闭应用程序时,终止功能未被调用)

Is it a good practise to set the Application should get App Died events flag? ( I set the "Application should get App Died events" and even then on closing the app from the multitasking dock the terminate function did not get called)

注册UIApplicationWillTerminateNotification比info.plist设置更好吗?

Is registering for "UIApplicationWillTerminateNotification" a better thing to do than the info.plist setting?

基本上我需要做有些工作仅在应用程序终止时工作,而不是在移动到后台时工作。

Basically I need to do some work only when the app terminates and NOT when it moves to background.

编辑(1) :
当应用程序终止时,以下内容将发送到APP。我怎么抓住它?

EDIT (1): When the app is terminated the following is sent to the APP. How do I catch it?

收到的节目信号:SIGKILL。

Program received signal: "SIGKILL".

编辑(2) ):

请注意:从多任务底座上卸下时,不会在IOS 4及更高版本中调用它。你可能会认为是。但就我而言,事实并非如此。

Please note : It is not getting called in IOS 4 and above when removing from the multitasking dock. You might think it is. But in my case it is not.

我在问是否有人知道为什么?还有别的我想念的东西。

I am asking if anyone knows why? Is there something else I am missing.

另请注意我设置了应用程序应该得到应用程序死亡事件,即使这样也没有被调用。

Also Note I set the "Application should get App Died events" and even then it is not getting called.

编辑(3):

以下问题的答案也不起作用。
不会调用applicationWillTerminate

The answer for the following question also did not work. applicationWillTerminate does not get invoked

任何人都面临与我类似的问题?

Anybody facing the similar issue as me?

推荐答案

简而言之,除非你有您的Info.plist中的UIApplicationExitsOnSuspend 设置为YES,在iOS4及更高版本中,无法保证 applicationWillTerminate:将被调用。

In short, unless you have UIApplicationExitsOnSuspend in your Info.plist set to YES, in iOS4 and above there is no guarantee that applicationWillTerminate: will ever get called.

作为文档说:


对于支持后台执行的应用程序,当用户退出应用程序时,通常不会调用此方法
,因为
应用程序在这种情况下只是移动到后台。但是,这个
方法可能在应用程序以
运行后台(未暂停)的情况下被调用,并且系统需要因某种原因终止它

For applications that support background execution, this method is generally not called when the user quits the application because the application simply moves to the background in that case. However, this method may be called in situations where the application is running in the background (not suspended) and the system needs to terminate it for some reason

(强调我的。)

如果你以前需要做点什么你需要在 applicationDidEnterBackground:中退出应用程序。没有办法抓住SIGKILL。

If you need to do something before the app exits you need to do it in applicationDidEnterBackground:. There is no way to catch SIGKILL.

这篇关于applicationWillTerminate何时被调用,何时不被调用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆