starwar2012 2012-11-22 05:54 采纳率: 0%
浏览 3566
已采纳

UILocalNotification每分钟重复

我想每隔一分钟发送本地通知,写出的代码:

[[UIApplication sharedApplication] cancelAllLocalNotifications];

    UILocalNotification *notif = [[UILocalNotification alloc] init];

    if (notif == nil) {
        return;
    }

    notif.timeZone = [NSTimeZone defaultTimeZone];

    notif.alertBody = @"Test notification!";
    notif.alertAction = @"View";
    notif.soundName = UILocalNotificationDefaultSoundName;
    notif.applicationIconBadgeNumber += 1;

    notif.repeatInterval = NSMinuteCalendarUnit;

    [[UIApplication sharedApplication] scheduleLocalNotification:notif];

但是它只发送一次就不再发送了。不知道怎么改。请大家帮忙解决。

  • 写回答

1条回答

  • LPPloveROU 2012-11-22 06:38
    关注

    你要给通知设置一个firedate,不然应用就会这样,通知立即发送,然后不重复。

    firedate根据制定的时间值执行,如果指定的时间值是空,或者已经过期了,那么通知就会立即发送

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 opencv 无法读取视频
  • ¥15 用matlab 实现通信仿真
  • ¥15 按键修改电子时钟,C51单片机
  • ¥60 Java中实现如何实现张量类,并用于图像处理(不运用其他科学计算库和图像处理库))
  • ¥20 5037端口被adb自己占了
  • ¥15 python:excel数据写入多个对应word文档
  • ¥60 全一数分解素因子和素数循环节位数
  • ¥15 ffmpeg如何安装到虚拟环境
  • ¥188 寻找能做王者评分提取的
  • ¥15 matlab用simulink求解一个二阶微分方程,要求截图