Question

I want to know if it is possible to add seconds to a local notification? I am trying to create a loop to schedule local notifications 30 seconds after each others. So, in the loop below, can I keep on "delaying" the firedate 30 seconds after each other. I don't know if that question makes sense, but that's the best I can describe my problem as. Think of it as a 30 second interval, but manually scheduling each notification.

for (notifs = 1, notifs <= 64, notifs ++)
{
  UILocalNotification* localNotification = [[UILocalNotification alloc] init];

localNotification.fireDate = [self.timePicker date]; 

//can i write it like [self.timePicker date] + 30000?

localNotification.soundName = @"notifsound.caf";
localNotification.alertBody = @"Wake Up!!!";
localNotification.timeZone = [NSTimeZone defaultTimeZone];         
}

Thanks.

Was it helpful?

Solution

You could use NSDate's dateByAddingTimeInterval: and just pass the current iteration number multiplied by 30.

for (notifs = 1; notifs <= 64; notifs ++)
{
    UILocalNotification* localNotification = [[UILocalNotification alloc] init];

    localNotification.fireDate = [[self.timePicker date] dateByAddingTimeInterval:notifs * 30.0];

    localNotification.soundName = @"notifsound.caf";
    localNotification.alertBody = @"Wake Up!!!";
    localNotification.timeZone = [NSTimeZone defaultTimeZone];

    [[UIApplication sharedApplication] scheduleLocalNotification:localNotification];
}
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top