应用程序已被打开之后,从通知中心中删除推 [英] Remove push from notificationcenter after app has been opened

查看:183
本文介绍了应用程序已被打开之后,从通知中心中删除推的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当我一个推送通知发送到我的应用程序,它停留在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屋!

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