作者热门文章
- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
如果用户将警报样式设置为横幅。他们可以收到多个通知,而不会提示他们清除通知。然后他们去使用电话,并且说了3个。如果单击最新的它并打开应用程序,则我只想清除此一条通知,我还需要输入badgeCount--;
如何使用下面的代码实现它? (此刻将清除所有我不想要的内容...)我还注意到有时它确实会更新徽章编号。但是,如果我切换回iOS主屏幕并下拉通知菜单,它仍然存在!
- (void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo
{
if([[userInfo valueForKey:@"aps"] valueForKey:@"alert"] != nil) {
NSString *message = [[userInfo valueForKey:@"aps"] valueForKey:@"alert"];
if(message != nil) {
UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:@"Usage Alert"
message:message delegate:self cancelButtonTitle:@"Cancel" otherButtonTitles:@"Ok", nil];
[alertView show];
[[UIApplication sharedApplication] setApplicationIconBadgeNumber: 0];
[[UIApplication sharedApplication] cancelAllLocalNotifications];
}
}
}
最佳答案
-(void)application:(UIApplication *)application didReceiveLocalNotification:(UILocalNotification *)notification
{
UIApplication *app = [UIApplication sharedApplication];
NSInteger badgeNumber = [app applicationIconBadgeNumber];// Take the current badge number
badgeNumber--; // decrement by one
[app setApplicationIconBadgeNumber:badgeNumber]; // set ne badge number
[app cancelLocalNotification:notification]; // cancel the received notification. It will clear the notification from banner alos
}
关于ios - 如何在iOS中仅清除通知,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15079545/
我是一名优秀的程序员,十分优秀!