UILocalNotification每分钟重复一次

时间:2012-11-21 09:55:40

标签: iphone ios ios5 uilocalnotification localnotification

我想每分钟发送本地通知,这是我正在使用的代码:

[[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 个答案:

答案 0 :(得分:2)

您必须为通知设置fireDate,否则不会重复,但会立即触发。

  

根据为其指定的值解释开火日期   时区。如果指定的值为nil或者是过去的日期,则为   通知立即发送。