简体   繁体   中英

Why local notification is repeated after 1 minute when the repeat interval is set 1 sec(NSSecCalendarUnit)?

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?

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM