打开应用程序后从通知中心删除推送 [英] Remove push from notificationcenter after app has been opened
本文介绍了打开应用程序后从通知中心删除推送的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
当我向我的应用程序发送 PUSH 通知时,它会停留在 iOS 5 的通知中心.如何从应用内的通知中心删除通知?
When I send out a PUSH notification to my app, it stays in the notification center in iOS 5. How can I remove the notification from the notification center from within the app?
推荐答案
清除徽章会清除通知中心的通知.
Clearing the badge clears the notifications from the notification center.
- (void)applicationDidBecomeActive:(UIApplication *)application {
// Clear application badge when app launches
[[UIApplication sharedApplication] setApplicationIconBadgeNumber:0];
}
这仅在数字更改时有效.因此,要使其在徽章已经为零的情况下工作,请将其设置为某个值并在延迟后再次清除.
This only works if the number changes. So to make it work in case badge is already zero, set it to some value and clear it again after a delay.
- (void)applicationWillEnterForeground:(UIApplication *)application {
if([[UIApplication sharedApplication] applicationIconBadgeNumber] == 0)
[[UIApplication sharedApplication] setApplicationIconBadgeNumber:1];
}
- (void)applicationDidBecomeActive:(UIApplication *)application {
// Clear application badge when app launches
[[UIApplication sharedApplication] setApplicationIconBadgeNumber:0];
}
如果您以相同的方法设置和清除,则不起作用.
Doesn't work if you set and clear in the same method.
这篇关于打开应用程序后从通知中心删除推送的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文