iPhone - 如何捕获应用程序是否终止(更新徽章图标)
我正在设置:
- (void)applicationWillTerminate:(UIApplication *)application
{
[UIApplication sharedApplication].applicationIconBadgeNumber = 1;
}
在我的应用程序委托中,但徽章从未更新...可能是什么问题?
当应用程序被终止时(手机关闭、任务栏应用程序终止、应用程序因内存过载而被系统终止,...),我该如何更新该徽章?
I'm setting :
- (void)applicationWillTerminate:(UIApplication *)application
{
[UIApplication sharedApplication].applicationIconBadgeNumber = 1;
}
in my application delegate but the badge is never updated... What can be the problem ?
How may I do to update that badge when the app is killed (phone shutdown, taskbar app kill, app killed by the system because of a memory overload, ...) ?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
当您的应用程序在后台终止时,它没有机会自行清理。应用程序在后台时已暂停;当它被杀死时,它只是从 RAM 中删除。您的徽章更新需要在此时间之前进行。
来自 Apple 文档:
还:
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.
From the Apple docs:
Also:
将
NSLog(@"App is being returned.");
放入您的-applicationWillTerminate:
方法中。我想您会发现当您按原样终止应用程序时不会调用此方法。您可以在应用程序正常执行期间或启动应用程序时设置应用程序的徽章图标。
Throw an
NSLog(@"App is being terminated.");
into your-applicationWillTerminate:
method. I think you'll find that this method isn't being called when you are terminating the app the way you are.You could set the application's badge icon during the app's normal execution or when the app is launched.
请仔细阅读 应用程序生命周期文档如下
另请尝试查看正在调用以下哪些方法
Please go over the app lifecycle documentation as below
Also try and see which of the below methods are being called