查看后如何删除通知中心的推送通知
点击后是否有任何处理来自通知中心的推送通知,并在我的应用程序已经启动时将其删除?
我知道这是黑客和斜杠,但您可以通过更改应用程序上的徽章号码来清除所有通知。
- (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]; ... }
如果你已经有一个徽章号码,你不想失去(上面的例子将简单地清除徽章号码),你可以做一些像
- (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]; ... }
这可能不是最好的做法,但它完成了工作,客户不知道其中的差别。 我喜欢把它叫做温度。 修复,直到我偶然find一个更好的解决scheme。 希望这可以帮助别人!