我为用户安排了多个本地通知。所有这些也都在指定的时间交付。但是,当我尝试从通知中心打开其中任何一个时,它们都被清除了。
在合理的情况下,我不希望所有这些都从通知中心清除,只有那些被点击打开的。
另外,我尝试在 AppDelegate.m 的代码下方评论,但问题仍然存在。 [[UIApplicationsharedApplication]setApplicationIconBadgeNumber:0];
谁能告诉我这可能是什么问题,即使我点击打开其中一个,我的预定通知也会从通知中心清除?
下面是我用来安排本地通知的代码 -
NSDateComponents *components = [SSUtility hoursMinuteAndSectionsForDate:date];
NSInteger hour = [components hour];
NSInteger minute = [components minute];
NSLog(@"Hour %ld Min %ld ", hour,minute);
UNCalendarNotificationTrigger *trigger = [UNCalendarNotificationTrigger triggerWithDateMatchingComponents:components repeats:YES];
/* Set notification */
UNMutableNotificationContent *content = [UNMutableNotificationContent new];
content.body = body;
// content.categoryIdentifier=NSNotificationC;
content.sound = [UNNotificationSound defaultSound];
content.userInfo = userInfo;
UNNotificationRequest *request = [UNNotificationRequest requestWithIdentifier:identifier
content:content
trigger:trigger];
UNUserNotificationCenter *center = [UNUserNotificationCenter currentNotificationCenter];
[center addNotificationRequest:request withCompletionHandler:^(NSError * _Nullable error) {
if (error != nil) {
SSLOG(@"Something went wrong: %@",error);
}
}];