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

查看:46
本文介绍了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. it is not called when pressing home button (as the app moves to background)

B.当从多任务 Dock 关闭应用程序时调用它,如果应用程序在 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)

基于此,我有几个问题

设置应用程序应该获取应用程序死亡事件标志是一个好习惯吗?(我设置了应用程序应该获取应用程序死亡事件",即使在从多任务码头关闭应用程序时也没有调用终止函数)

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天全站免登陆