摆脱应用程序图标上的 UILocalNotification
Getting rid of UILocalNotification on App Icon
我有一个待办事项列表应用程序,可以发送特定杂务的通知。一切正常,但带有通知数量的红色圆圈永远不会在图标上消失。我应该添加什么样的代码来摆脱这些?谢谢!
这里有一些代码(一切正常)只是为了给你要点
正在发送通知...
- (void)sendNotification {
NSString *choreTitle = [NSString stringWithFormat:@"%@", self.chore.title];
NSString *choreDetail = [NSString stringWithFormat:@"%@", self.chore.detail];
UILocalNotification* localNotification = [[UILocalNotification alloc] init];
if (localNotification) {
localNotification.fireDate = self.datePicker.date;
localNotification.timeZone = [NSTimeZone defaultTimeZone];
localNotification.repeatInterval = 0;
localNotification.soundName = @"bell_tree.mp3";
localNotification.alertBody = [NSString stringWithFormat: @"A friendly reminder, %@, %@", choreTitle, choreDetail];
localNotification.applicationIconBadgeNumber = 1;
[[UIApplication sharedApplication] scheduleLocalNotification:localNotification];
}
NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];
[dateFormatter setDateFormat:@"dd MMM yyyy HH:mm"];
NSDate *date = self.datePicker.date;
NSString *formattedDateString = [dateFormatter stringFromDate:date];
UIAlertController *alertController = [UIAlertController alertControllerWithTitle:[NSString stringWithFormat:@"An alert will be sent to you on %@",formattedDateString] message:nil preferredStyle:UIAlertControllerStyleAlert];
[alertController addAction:[UIAlertAction actionWithTitle:@"Okay!" style:UIAlertActionStyleCancel handler:^(UIAlertAction *action) {
[self dismissViewControllerAnimated:YES completion:nil];
}]];
[self presentViewController:alertController animated:YES completion:nil];
}
在应用委托中...
- (void)applicationDidBecomeActive:(UIApplication *)application {
if ([application respondsToSelector:@selector(registerUserNotificationSettings:)]) {
[application registerUserNotificationSettings:[UIUserNotificationSettings settingsForTypes:(UIUserNotificationTypeAlert | UIUserNotificationTypeBadge | UIUserNotificationTypeSound) categories:nil]];
}
}
地点
[[UIApplication sharedApplication] setApplicationIconBadgeNumber:0];
你的 applicationDidFinishLaunching
and/or applicationDidBecomeActive
.
我有一个待办事项列表应用程序,可以发送特定杂务的通知。一切正常,但带有通知数量的红色圆圈永远不会在图标上消失。我应该添加什么样的代码来摆脱这些?谢谢!
这里有一些代码(一切正常)只是为了给你要点
正在发送通知...
- (void)sendNotification {
NSString *choreTitle = [NSString stringWithFormat:@"%@", self.chore.title];
NSString *choreDetail = [NSString stringWithFormat:@"%@", self.chore.detail];
UILocalNotification* localNotification = [[UILocalNotification alloc] init];
if (localNotification) {
localNotification.fireDate = self.datePicker.date;
localNotification.timeZone = [NSTimeZone defaultTimeZone];
localNotification.repeatInterval = 0;
localNotification.soundName = @"bell_tree.mp3";
localNotification.alertBody = [NSString stringWithFormat: @"A friendly reminder, %@, %@", choreTitle, choreDetail];
localNotification.applicationIconBadgeNumber = 1;
[[UIApplication sharedApplication] scheduleLocalNotification:localNotification];
}
NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];
[dateFormatter setDateFormat:@"dd MMM yyyy HH:mm"];
NSDate *date = self.datePicker.date;
NSString *formattedDateString = [dateFormatter stringFromDate:date];
UIAlertController *alertController = [UIAlertController alertControllerWithTitle:[NSString stringWithFormat:@"An alert will be sent to you on %@",formattedDateString] message:nil preferredStyle:UIAlertControllerStyleAlert];
[alertController addAction:[UIAlertAction actionWithTitle:@"Okay!" style:UIAlertActionStyleCancel handler:^(UIAlertAction *action) {
[self dismissViewControllerAnimated:YES completion:nil];
}]];
[self presentViewController:alertController animated:YES completion:nil];
}
在应用委托中...
- (void)applicationDidBecomeActive:(UIApplication *)application {
if ([application respondsToSelector:@selector(registerUserNotificationSettings:)]) {
[application registerUserNotificationSettings:[UIUserNotificationSettings settingsForTypes:(UIUserNotificationTypeAlert | UIUserNotificationTypeBadge | UIUserNotificationTypeSound) categories:nil]];
}
}
地点
[[UIApplication sharedApplication] setApplicationIconBadgeNumber:0];
你的 applicationDidFinishLaunching
and/or applicationDidBecomeActive
.