NTNT
NTNT

Reputation: 541

Repeat Interval for UILocalNotification every 10s

I want to make the UILocalNotification with the date user selected, but if user does not tap on the Notification bar to launch app, will continue to push the Local notification after 10s. That means the app will push the 2 Local notifications:

  1. The main Local notification with the date time user selected
  2. The repeat local notification every 10s.

I tried this code but it's not work:

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

reminderNote.fireDate = [NSDate dateWithTimeIntervalSinceNow:10];
[[UIApplication sharedApplication] scheduleLocalNotification:reminderNote];

Thanks in advance.

Upvotes: 1

Views: 594

Answers (2)

tktsubota
tktsubota

Reputation: 9391

There are a couple things wrong with this:

  1. You cannot repeat UILocalNotification's that frequently. From the Apple documentation:

Note that intervals of less than one minute are not supported.

  1. You can only repeat by standard NSCalendarUnit intervals, like every hour, every day, or every month. See this post for more information.

Upvotes: 2

Mihir Mehta
Mihir Mehta

Reputation: 13833

I think you need to create separate object for UILocalNotification

create 2 different UILocalNotification object and fire it at different time

like

-(void) fireAtDate:(NSDate *) date {

    UILocalNotification *reminderNote = [[UILocalNotification alloc]init];
    reminderNote.fireDate = _selectedDate;
    reminderNote.repeatInterval = NSSecondCalendarUnit;
    reminderNote.alertBody = @"some text";
    reminderNote.alertAction = @"View";
    reminderNote.soundName = @"sound.aif";


    reminderNote.fireDate = date;
    [[UIApplication sharedApplication] scheduleLocalNotification:reminderNote];
}

...

[self fireDate([NSDate dateWithTimeIntervalSinceNow:0])];
[self fireDate([NSDate dateWithTimeIntervalSinceNow:10])];

Upvotes: 0

Related Questions