编辑:我正在设置 365 个本地通知 UNUserNotification (每年每天一个)。按钮一次调用:
[self name1];
[self name2];
...
[self name365];
- 每天一个名字。如果我只尝试例如。3天,完美运行。如果我整天打电话(365x),它只会触发最后一个本地通知(仅限 365.) - 错过了第 1-364 天(未触发)。有任何想法吗?
代码:
-(void)Name1{
NSDateComponents *comps = [[NSDateComponents alloc] init];
comps.hour = 9;
comps.minute = 0;
comps.day = 23;
comps.month = 10;
UNMutableNotificationContent *objNotificationContent = [[UNMutableNotificationContent alloc] init];
objNotificationContent.title = [NSString localizedUserNotificationStringForKey:@"NAME" arguments:nil];
objNotificationContent.body = [NSString localizedUserNotificationStringForKey:@"text"
arguments:nil];
objNotificationContent.sound = [UNNotificationSound soundNamed:@"notif_bobicek.mp3"];
UNCalendarNotificationTrigger *trigger = [UNCalendarNotificationTrigger triggerWithDateMatchingComponents: comps repeats:YES];
UNNotificationRequest *request = [UNNotificationRequest requestWithIdentifier:@"requestNotificationForName1"
content:objNotificationContent trigger:trigger];
UNUserNotificationCenter *center = [UNUserNotificationCenter currentNotificationCenter];
[center addNotificationRequest:request withCompletionHandler:^(NSError * _Nullable error) {
if (!error) { NSLog(@"Local Notification succeeded"); }
else { NSLog(@"Local Notification failed"); }}];
}
.
-(void)Name2{ ... // same code
-(void)Name365{... // same code
注意:每个计划的本地通知的标识符都不同。