[英]Clear notifications from the notification center on button click
我想通过单击应用程序内存在的按钮来从通知中心清除应用程序的本地推送通知。
在10之前的iOS上,您只能通过将applicationIconBadgeNumber
设置为0来实现。在iOS 10上,您可以使用UNUserNotificationCenter
框架修改单个通知。
请使用此代码,它将为您提供帮助
[[UIApplication sharedApplication] setApplicationIconBadgeNumber:1];
[[UIApplication sharedApplication] setApplicationIconBadgeNumber:0];
// To remove the notifications in Notification Center:
[[UIApplication sharedApplication] cancelAllLocalNotifications];
尝试这个
int badgeCount = [UIApplication sharedApplication].applicationIconBadgeNumber;
[[UIApplication sharedApplication] setApplicationIconBadgeNumber:0];
[[UIApplication sharedApplication] cancelAllLocalNotifications];
[[UIApplication sharedApplication] setApplicationIconBadgeNumber:badgeCount];
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.