UILocalNotifications repeatInterval using NSWeekdayCalendarUnit

OK, so I saw several messages saying that you cannot set UILocalNotification to repeat more or less than a few given parameters (every minute / hour / day / week / month, etc.).

However, none of these messages indicated which repeatInterval setting repeatInterval from UILocalNotification to NSWeekdayCalendarUnit .

I am very new to all NSDate and NSCalendar stuff, so I'm sure something is missing, but I read the documentation and it looks like you can use NSWeekdayCalendarUnit to repeat NSLocalNotification let's say every Monday, Tuesday and Thursday if NSWeekdayCalendarUnit set to 2 , 3.5.

NSWeekdayCalendarUnit Indicates the block of the week. The corresponding value is int. Equals kCFCalendarUnitWeekday. Weekday units are numbers from 1 to N (where for the Gregorian calendar, N = 7 and 1 is Sunday).

Is this wrong?

Thanks in advance.

+4
source share
1 answer

Yes, you can. I do it like this. The user can select the scheme using the collector. And then the selection proceeds to the following method:

 - (void)setOneLocalAlarmNotification: (NSDate *)firstFireDate withRepeat: (NSInteger)repeat { UILocalNotification *localNotif = [[UILocalNotification alloc] init]; if (localNotif == nil) return; localNotif.fireDate = firstFireDate; localNotif.timeZone = [NSTimeZone defaultTimeZone]; localNotif.repeatCalendar = [NSCalendar currentCalendar]; switch(repeat) { case 0: break ; case 1: localNotif.repeatInterval = kCFCalendarUnitDay; break; case 2: localNotif.repeatInterval = kCFCalendarUnitWeekday; break; default: break; } // Notification details localNotif.alertBody = @"Message?"; // Set the action button localNotif.alertAction = @"Yes"; localNotif.soundName = @"glas.caf"; //UILocalNotificationDefaultSoundName; localNotif.applicationIconBadgeNumber = 1; // Specify custom data for the notification NSDictionary *infoDict = [NSDictionary dictionaryWithObject:@"Alarm" forKey:@"type"]; localNotif.userInfo = infoDict; // Schedule the notification [[UIApplication sharedApplication] scheduleLocalNotification:localNotif]; [localNotif release] } 
+1
source

Source: https://habr.com/ru/post/1342188/


All Articles