在应用程序激活时关闭本地通知 [英] Dismiss local notifications when application becomes active

查看:65
本文介绍了在应用程序激活时关闭本地通知的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在开发一个IM应用程序,该应用程序在后台运行时保持连接打开一段时间,并使用本地通知向用户发出有关新传入消息的警报.

I am developing an IM application that keeps connection open for some time when application is backgrounded and uses local notifications to alert user about new incoming messages.

以前,在iOS 4上,在使用-[UIApplication presentLocalNotificationNow:] 呈现新的本地通知之前,先调用-[UIApplication cancelAllLocalNotifications] .这样一来,屏幕上总是只显示最新的通知.

Previously, on iOS 4, -[UIApplication cancelAllLocalNotifications] was called before presenting a new local notification using -[UIApplication presentLocalNotificationNow:]. This way always only the latest notification was present on the screen.

自从iOS 5引入通知中心以来,该解决方案已不再被接受,因为我们希望在那里显示最后一条消息.但是,我们也想在应用程序激活时关闭所有本地通知警报.我该怎么做呢?我想我应该在某个时候打电话给-[UIApplication cancelAllLocalNotifications] ,但是我不确定在哪里.谢谢您的帮助.

Since iOS 5 introduced Notification Center, this solution is not acceptable anymore because we want to have more that one last message displayed there. But also we want to close all local notification alerts when application becomes active. How do I better do that? I suppose I should call -[UIApplication cancelAllLocalNotifications] at some point, but I'm not sure where. Ahy help will be appreciated.

推荐答案

尝试在应用程序委托的 apllicationWillEnterForeground 方法中调用-[UIApplication cancelAllLocalNotifications] .

Try calling -[UIApplication cancelAllLocalNotifications] in the apllicationWillEnterForeground method of your app delegate.

查看更多信息此处.

这篇关于在应用程序激活时关闭本地通知的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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