EDIT: I am setting exactly 365 local notifications UNUserNotification (one for each day a year). Button is calling at one time:
[self name1];
[self name2];
...
[self name365];
- one name for every day. If I try only eg. 3 days, it works perfectly. If I call all days (365x), it fires only the last local notification (365. only) - day 1-364 is missed (not fired). Any ideas?
Code:
-(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
Note: Identifier is different for each scheduled local notification.
This does not answer your question directly and you really should parameterise your approach, but what I will show you can help a lot. I want to illustrate clearly what I meant with using #define in my comment.
Using #define is a powerful way to solve some tricky problems and even here it can make your life a lot easier. Think of #define as a type of search and replace, which it literally used to be, and here you can use that to define your message ONCE and then replace it 365 times in stead of creating 365 different messages. Here is an outline.
If you parameterise your approach but still need 365 functions you can e.g. expand the #define by adding more parameters. Anyhow, for more info see this really nice reference.
https://en.wikibooks.org/wiki/C_Programming/Preprocessor_directives_and_macros
HIH