Creating week intervals in UILocalNotification along with a loop

I am creating an application using UILocalNotification. I want to know how to make spaces in UILocalNotification, that is, how can I set the alarm for 4 weeks (repeat every day or once a day) and exit for 1 week and again for 4 weeks and for 1 week and so on . This is just one case. These spaces are dynamic and are resolved at runtime.

+6
source share
2 answers

You will not be able to use repeatInterval , since you need a special repetition scheme. I think you need to schedule a local notification every day when you want to receive it:

  • 28 notifications for every day of the first 4 weeks,
  • 28 notifications for each day of the second period of 4 weeks,
  • etc.

Some code that might help:

 /** This method will schedule 28 notifications, each 24 hours exactly for 4 weeks, starting from dayOne (first notification will be at dayOne, the second one at dayOne + 24 hours..., so be sure to choose the hour you want by setting dayOne correctly. */ - (void)scheduleLocalNotificationsEachDayFor4WeeksStartingFrom:(NSDate *)dayOne { // Schedule notifications for each day during 4 weeks starting at dayOne NSMutableArray *notifications = [NSMutableArray array]; for (int i = 0; i < 28; i++) { [notifications addObject:notificationForDay(dayOne, i)]; } for (UILocalNotification *notification in notifications) { [[UIApplication sharedApplication] scheduleLocalNotification:notification]; } } UILocalNotification *notificationInSomeDays(NSDate *referenceDate, NSUInteger some) { UILocalNotification *notification = [[[UILocalNotification alloc] init] autorelease]; // Notification timing NSUInteger days = 60*60*24; // number of seconds in a day notification.fireDate = [referenceDate dateByAddingTimeInterval:some * days]; notification.timeZone = [NSTimeZone localTimeZone]; // use local time zone if your reference date is a local one, or choose the appropriate time zone // define your notification content... return notification; } 

You can use the scheduleLocalNotificationsEachDayFor4WeeksStartingFrom: method to schedule the 28 notifications required for each 4-week period. That way, you can simply run it as often as needed, invoking it from the first day of each period of 4 weeks, when you want notifications to start.

When you launch the application, you should clear all current local notifications and transfer them according to your requirements. In particular, you will need to configure whether the application will be launched within 4 weeks, when notifications should be launched. In this case, you will have to configure the proposed scheduleLocalNotificationsEachDayFor4WeeksStartingFrom method to reduce the number of scheduled notifications ...

0
source

It means to say that these chaos are dynamic .... so if she sets 28 notifications in the first 4 weeks and 28 notifications in the second period, etc .... then it will cross 64 local notifications per application .... .. also these gaps are dynamic, which means that it can be anything, suppose 12 weeks a week for 1 week ..... then, according to the ur method, she should set 84 notifications for one medicine (restriction of crosses), and they certainly more than one medicine of this kind ...

0
source

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


All Articles