问题
I am trying to schedule a local notificaition that will repeat after every 1 sec once the notification is fired. The notification is fired 10 sec after the application starts.
UILocalNotification *notif = [[cls alloc] init];
notif.fireDate = [[NSDate alloc]initWithTimeInterval:10 sinceDate:[NSDate date]];
notif.timeZone = [NSTimeZone defaultTimeZone];
notif.alertBody = @"Did you forget something?";
notif.alertAction = @"Show me";
//notif.soundName = UILocalNotificationDefaultSoundName;
notif.soundName = @"applause-light-01.wav";
notif.applicationIconBadgeNumber = 1;
notif.repeatInterval = NSSecondCalendarUnit;
[[UIApplication sharedApplication] scheduleLocalNotification:notif];
Even thought I have used notif.repeatInterval = NSSecondCalendarUnit
, notification repeat after 60 sec. What is that I am doing wrong?
回答1:
notif.fireDate = [[NSDate alloc]initWithTimeInterval:10 sinceDate:[NSDate date]];
This line of code makes your local notification to fire after the new date is created. If you want the notifications right away then you should just create a simple date like this,
notif.fireDate = [NSDate date];
Hope this helps.
来源:https://stackoverflow.com/questions/13644357/why-local-notification-is-repeated-after-1-minute-when-the-repeat-interval-is-se