当重复间隔设置为 1 秒(NSSecCalendarUnit)时,为什么会在 1 分钟后重复本地通知? [英] Why local notification is repeated after 1 minute when the repeat interval is set 1 sec(NSSecCalendarUnit)?

查看:28
本文介绍了当重复间隔设置为 1 秒(NSSecCalendarUnit)时,为什么会在 1 分钟后重复本地通知?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试安排一个本地通知,一旦通知被触发,它将在每 1 秒后重复一次.应用程序启动后 10 秒会触发通知.

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];

甚至以为我使用了 notif.repeatInterval = NSSecondCalendarUnit,60 秒后通知重复.我做错了什么?

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];

希望这会有所帮助.

这篇关于当重复间隔设置为 1 秒(NSSecCalendarUnit)时,为什么会在 1 分钟后重复本地通知?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆