iPhone本地通知和UIDatePicker:如何设置每日重复的横幅通知/警报

时间:2013-07-15 16:06:29

标签: notifications nsdate uilocalnotification uidatepicker

我目前设置了本地通知,以便用户可以在发送通知时选择datePicker(小时,分钟和上午/下午)的时间。它工作正常......直到第二天。似乎通知仅在同一天工作,并在午夜点击时重置。如何防止警报重置,以便每天发送通知?

到目前为止,这是我的代码:

(IBAction)scheduleNotification:(id)sender {
    UILocalNotification *notification = [[UILocalNotification alloc]init];
    NSDate *fireDate = _datePicker.date;
    [notification setFireDate:fireDate];
    [notification setAlertBody:@"Daily Reminder"];
    [notification setAlertAction:@"Go to app"];

    [[UIApplication sharedApplication]scheduleLocalNotification:notification];

//Local push notifications
}

(IBAction)didChangeDatePicker:(id)sender {
    NSLog(@"New reminder time selected: %@",self.datePicker.date);
}

1 个答案:

答案 0 :(得分:1)

您需要添加:

[notification setRepeatInterval:NSDayCalendarUnit];

然后每天都会重复,直到您取消它:

[[UIApplication sharedApplication] cancelLocalNotification:notification];

[[UIApplication sharedApplication] cancelAllLocalNotifications];

顺便说一下,它只会取消您应用设置的通知。

如果你在UILocalNotification上搜索,那么这在文档中很好地展示了。