3

I'm trying here to repeat a local notification for every hour. so I tried this sample code:

UILocalNotification *reminderNote = [[UILocalNotification alloc]init];
    reminderNote.fireDate = [NSDate dateWithTimeIntervalSinceNow:60 * 60];
    reminderNote.repeatInterval = NSDayCalendarUnit;
    reminderNote.alertBody = @"some text";
    reminderNote.alertAction = @"View";
    reminderNote.soundName = @"sound.aif";
    [[UIApplication sharedApplication] scheduleLocalNotification:reminderNote];

and it worked fine. But when I try to repeat it at a specific minute of the hour, say every hour sharp, or every hour and 6 mins. I just couldn't figure out a way to do that! I tried to change SinceNow to anything else but it's not working!

Is there a way change it? or any other sample code that I should work on?

Thanks in Advance.

user1949873
  • 460
  • 7
  • 17
  • Related post here..http://stackoverflow.com/questions/3820428/uilocalnotification-problem – alex Jan 09 '13 at 13:48

2 Answers2

1
reminderNote.repeatInterval = NSHourCalendarUnit;
P.J
  • 6,547
  • 9
  • 44
  • 74
Amit Battan
  • 2,968
  • 2
  • 32
  • 68
  • but how to specify the minute? – user1949873 Jan 09 '13 at 13:34
  • in minutes..... yourNotificationObject.repeatInterval = NSMinuteCalendarUnit; and in seconds yourNotificationObject.repeatInterval = NSSecondCalendarUnit; – aakil nikil Jun 09 '14 at 10:41
  • question is not answered correctly. @P.J your code will repeat every hour but here requirement is of every hour and 6 minutes. – Dheeraj Gupta Apr 21 '18 at 13:22
  • @DheerajGupta My role is just editor here, nothing more. If you want answer to this question, it has already been answered in previous answer – P.J Apr 21 '18 at 14:38
1

If the repeat interval between the first and the second reminder repetition is different from the interval for the rest, you need to define a new local notification with the correct fire date, e.g. 6 minutes after the hour. Then set the repeat interval to the NSHourCalendarUnit.

You can specify the interval with the usual pattern with NSCalendar and NSDateComponents. This is well documented here.

Mundi
  • 79,884
  • 17
  • 117
  • 140
  • Thank you. But it's actually all the intervals are the same for now. So for example, I want the notification to fire 7 minutes after the hour... Now when I tried the code provided above. It actually started counting from the minute the app became active. Not from a specified minute. As it stated SinceNow.. "reminderNote.fireDate = [NSDate dateWithTimeIntervalSinceNow:60 * 60];" – user1949873 Jan 09 '13 at 14:31
  • Well, don't use "sinceNow". Use the date computed with the correct minute! – Mundi Jan 09 '13 at 15:46
  • I did what you said but it's still not working. I tried to show you my work here but there isn't enough space so I'll post the new code in a new question. Thanks a lot for your notes. – user1949873 Jan 09 '13 at 21:43
  • You *can* post more code in the question. I would be happy to look at it. – Mundi Jan 09 '13 at 23:00
  • can you please check out my new question.. [link](http://stackoverflow.com/questions/14247784/whats-wrong-with-my-notification-code) – user1949873 Jan 10 '13 at 00:24