UilocalNotification每15分钟一次,但不是在晚上(晚上10点以后)

时间:2016-03-16 14:24:51

标签: ios objective-c uilocalnotification

我想每15分钟发一次UILocalNotification。这没问题:

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

    notification.fireDate = [[NSDate date] dateByAddingTimeInterval:15];
    notification.repeatInterval = NSMinuteCalendarUnit;



    notification.alertBody = NSLocalizedString(@"Alert", @"");
    notification.timeZone = [NSTimeZone defaultTimeZone];
    notification.soundName = UILocalNotificationDefaultSoundName;

    [[UIApplication sharedApplication] scheduleLocalNotification:notification];

但我想在上午8点到晚上10点之间做到这一点。我该怎么处理?

1 个答案:

答案 0 :(得分:0)

您必须使用repeaInterval,您可能会想到每15分钟重复一次通知,但如果您想跳过小时,则会遇到问题。 您还可以安排一天的所有通知(在上午7:00,上午7:15,上午7:30等添加一个),并重复一次,间隔为1天。如果你想要每小时4次通知,从早上7点到晚上10点就会发出60次通知(最多64次)。