0

I using below code for LocalNotification for every day.

NSDate * datetime = reminder.fireTime;
NSCalendar *cal = [NSCalendar currentCalendar];
NSDateComponents *components = [cal components:(NSCalendarUnitHour | NSCalendarUnitMinute | NSCalendarUnitSecond)fromDate:datetime];
components.timeZone = [NSTimeZone defaultTimeZone];

UNCalendarNotificationTrigger *triggerCalender = 
    [UNCalendarNotificationTrigger triggerWithDateMatchingComponents:components 
                                                             repeats:YES];
UNMutableNotificationContent *content = [[UNMutableNotificationContent alloc] init];
content.title = NOTIFICATION_REMINDER_TITLES;
content.body = NOTIFICATION_REMINDER_MESSAGES;
UNNotificationRequest *request = 
    [UNNotificationRequest requestWithIdentifier:[NSString stringWithFormat:FORMAT_KEY_NOTIFICATION, REMINDER_TITLES[type]] 
                                         content:content 
                                         trigger:triggerCalender];

It's working fine apart from 1 condition. When scheduled time is 1-day ahead.

Example: - Current time (7:00 AM) Now I am trying to schedule notification from tomorrow onward at 7:30 AM. So local notification should start from tomorrow onward (This is my requirement).

But its schedule for today as well as. So I want to ignore today notification. How can I achieve this?

Chandan kumar
  • 1,074
  • 12
  • 31
  • you need to change the date when you want to fire the notification. NSDate * datetime = reminder.fireTime; what does reminder.time hold ? – Teja Nandamuri Jun 15 '17 at 19:46
  • Its hold next day date. I think issue with NSDateComponents – Chandan kumar Jun 15 '17 at 19:52
  • Possible duplicate of [Fire a notification at a specific day and time every week](https://stackoverflow.com/questions/20110805/fire-a-notification-at-a-specific-day-and-time-every-week) – Teja Nandamuri Jun 15 '17 at 20:03
  • Some searching indicates that it is *not* possible to do what you want - i.e. "skip the first notification". However... you might want to read through this article. It's Swift not Obj-C, but the principal is the same. I don't know if it will solve your task, but maybe.... https://makeapppie.com/2017/01/31/how-to-repeat-local-notifications/ – DonMag Jun 15 '17 at 20:43
  • Thanks, @DonMag for understanding the question. I will check the tutorial. – Chandan kumar Jun 15 '17 at 20:56
  • @DonMag tutorial does not solve my problem. – Chandan kumar Jun 15 '17 at 21:34
  • @Chandan Did you find any solution for this? Came across similar requirement – Anmol Suneja Aug 23 '20 at 07:41

0 Answers0