如何在查看后删除通知中心中的推送通知 [英] How to Remove Push Notification in Notification Center after viewed

查看:222
本文介绍了如何在查看后删除通知中心中的推送通知的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

点击后是否有办法处理通知中心的推送通知,并在我的应用程序启动后将其删除?

Is there any way to handle the push notification from the Notification Center after being tap, and remove it when my application has already launched?

推荐答案

我知道这是破解和削减,但您可以通过更改应用程序上的徽章编号来清除所有通知。

I know this is hack and slash, but you can clear all notifications by changing the badge number on your application.

- (void)application:(UIApplication*)application didReceiveRemoteNotification (NSDictionary*)payload
{
    NSLog(@"Received notification: %@", payload);
    //swapping between two badge numbers to clear notifications
    [[UIApplication sharedApplication] setApplicationIconBadgeNumber:1];
    [[UIApplication sharedApplication] setApplicationIconBadgeNumber:0];
    ...
}

如果您已经有徽章编号不想丢失(上面的例子只是简单地清楚徽章编号)你可以做类似的事情

If you already had a badge number you don't want to lose (above example will simply clear badge number in the end) you can do something like

- (void)application:(UIApplication*)application didReceiveRemoteNotification (NSDictionary*)payload
{
    NSLog(@"Received notification: %@", payload);
    /*
     storing current badge number then swapping between 2 values to make sure we 
     clear the badge number. Once this is done set badge number back to original 
     value.
    */
    int badgeNum = [[UIApplication sharedApplication] applicationIconBadgeNumber]
    [[UIApplication sharedApplication] setApplicationIconBadgeNumber:1];
    [[UIApplication sharedApplication] setApplicationIconBadgeNumber:0];
    [[UIApplication sharedApplication] setApplicationIconBadgeNumber:badgeNum];
    ...
}

这可能不是最佳做法,但它完成工作,客户不会知道差异。我喜欢称它为临时。修复,直到我偶然发现一个更好的解决方案。希望这有助于某人!

This may not be best practice, but it gets the job done and the client will not know the difference. I like to call it a temp. fix until I stumble upon a better solution. Hope this helps someone!

这篇关于如何在查看后删除通知中心中的推送通知的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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