繁体   English   中英

在应用程序图标上摆脱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和/或applicationDidBecomeActive

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM