I want to fire an UILocalNotification every 15 minutes. That is no problem:
我想每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];
But I would like to do that only between 8am and 10pm. How can I handle that?
但我想在上午8点到晚上10点之间做到这一点。我该怎么处理?
1 个解决方案
#1
0
You will have to use repeaInterval
, you probably think of repeat the notification every 15 min, but you have a problem if you want to skip hours. You could also schedule all notifications for one day (add one for 7:00am, 7:15am, 7:30am, etc) and repeat them for an interval of 1 day. If you want 4 notifications per hour, from 7am to 10pm that makes 60 notifications (which is under the max 64).
您将不得不使用repeaInterval,您可能会想到每15分钟重复一次通知,但如果您想跳过几小时,则会遇到问题。您还可以安排一天的所有通知(在上午7:00,上午7:15,上午7:30等添加一个)并重复1天的间隔。如果您希望每小时发送4个通知,则从早上7点到晚上10点会发出60个通知(最多64个通知)。
#1
0
You will have to use repeaInterval
, you probably think of repeat the notification every 15 min, but you have a problem if you want to skip hours. You could also schedule all notifications for one day (add one for 7:00am, 7:15am, 7:30am, etc) and repeat them for an interval of 1 day. If you want 4 notifications per hour, from 7am to 10pm that makes 60 notifications (which is under the max 64).
您将不得不使用repeaInterval,您可能会想到每15分钟重复一次通知,但如果您想跳过几小时,则会遇到问题。您还可以安排一天的所有通知(在上午7:00,上午7:15,上午7:30等添加一个)并重复1天的间隔。如果您希望每小时发送4个通知,则从早上7点到晚上10点会发出60个通知(最多64个通知)。