删除应用图标上的徽章的代码是什么?当我收到推送时,我需要在单击按钮时将其删除!
答案 0 :(得分:95)
objC :
[UIApplication sharedApplication].applicationIconBadgeNumber = 0;
swift :
UIApplication.sharedApplication().applicationIconBadgeNumber = 0;
答案 1 :(得分:9)
您可以通过在代码中添加以下行来删除推送通知中的徽章
(void)applicationDidBecomeActive:(UIApplication *)application
{
[[UIApplication sharedApplication] cancelAllLocalNotifications];
[UIApplication sharedApplication].applicationIconBadgeNumber = 0;
}
答案 2 :(得分:7)
对于iOS5,只设置徽章编号不会删除通知中心的推送通知。你必须这样做......
[[UIApplication sharedApplication] cancelAllLocalNotifications];
[UIApplication sharedApplication].applicationIconBadgeNumber = 0;
我已经测试了这个。看起来cancelAllLocalNotifications
方法也适用于通知中心的推送通知。
答案 3 :(得分:1)
Swift 3
File output=new File("C:\\\\MDU-1617-CSJ0098\\\\web\\\\products.txt");
BufferedWriter writer1 = new BufferedWriter(new FileWriter(output));
while(q_set2.next()) {
String s=String.valueOf(q_set2.getInt(1));
System.out.print(s);
writer1.write(s);
writer1.newLine();
}
writer1.flush(); // or writer1.close();
可以添加到以下方法中:
UIApplication.shared.applicationIconBadgeNumber = 0
和
optional public func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey : Any]? = nil) -> Bool