1

我目前设置了本地通知,以便用户可以在 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);
}
4

1 回答 1

1

您需要添加:

[notification setRepeatInterval:NSDayCalendarUnit];

然后它将每天重复发生,直到您通过以下方式取消它:

[[UIApplication sharedApplication] cancelLocalNotification:notification];

或者

[[UIApplication sharedApplication] cancelAllLocalNotifications];

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

同样,如果您在UILocalNotification.

于 2013-07-18T23:49:00.037 回答