iPhone-如何捕获应用程序是否终止(更新徽章图标) [英] iPhone - How to catch if the app is terminated (to update the badge icon)

查看:85
本文介绍了iPhone-如何捕获应用程序是否终止(更新徽章图标)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在设置:

- (void)applicationWillTerminate:(UIApplication *)application
{
    [UIApplication sharedApplication].applicationIconBadgeNumber = 1;
}

在我的应用程序委托中,但徽章从未更新过……可能是什么问题?

in my application delegate but the badge is never updated... What can be the problem ?

当应用程序被杀死(电话关闭,任务栏应用程序被杀死,由于内存过载而被系统杀死的应用程序...)时,我该如何更新该标志?

推荐答案

当您的应用在后台终止时,它没有机会自行清理.后台运行时,该应用已被暂停;被杀死时,它只是从RAM中删除.您的徽章更新需要在此之前进行.

When your app is terminated in the background, it does not get an opportunity to clean up after itself. The app is already suspended when backgrounded; when killed it is just removed from RAM. Your badge updates need to happen before that time.

摘自Apple文档:

已暂停 该应用程序在后台运行,但未执行代码.系统会自动将应用程序移至此状态,并且在执行此操作之前不会通知它们.挂起时,应用程序仍保留在内存中,但不执行任何代码. 当内存不足的情况发生时,系统可能会清除挂起的应用程序而不会发出通知,从而为前景应用程序腾出更多空间.

Suspended The app is in the background but is not executing code. The system moves apps to this state automatically and does not notify them before doing so. While suspended, an app remains in memory but does not execute any code. When a low-memory condition occurs, the system may purge suspended apps without notice to make more space for the foreground app.

也:

applicationWillTerminate:-让您知道您的应用程序正在终止.如果您的应用已暂停,则不会调用此方法.

applicationWillTerminate:—Lets you know that your app is being terminated. This method is not called if your app is suspended.

这篇关于iPhone-如何捕获应用程序是否终止(更新徽章图标)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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