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

て烟熏妆下的殇ゞ 提交于 2020-01-02 07:21:29

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!