Reputation: 2609
I am scheduling a local notification. My problem is that Recurring notifications can only be scheduled on an interval of every hour, every day, every week, every month, or every year. You do not have an option of “every 2 hours”.
Now, I want to schedule it for every 2 or 3 hours of time interval. Also as there is a limitation of iOS to schedule only 64 notification at a time.
Please note that I can not use push notification.
How can I achieve this ?
Upvotes: 1
Views: 1259
Reputation: 859
2 Hours = 60 secs * 60 min *2 = 7200 secs. Will this work? if you use 7200 in TimeInterval in following code which is for five second (from Apple website)
let content = UNMutableNotificationContent()
content.title = NSString.localizedUserNotificationStringForKey("Hello!", arguments: nil)
content.body = NSString.localizedUserNotificationStringForKey("Hello_message_body", arguments: nil)
content.sound = UNNotificationSound.default() // Deliver the notification in five seconds.
let trigger = UNTimeIntervalNotificationTrigger(timeInterval: 5, repeats: false)
let request = UNNotificationRequest(identifier: "FiveSecond", content: content, trigger: trigger) // Schedule the notification.
let center = UNUserNotificationCenter.current()
center.add(request)
EDIT: Please see similar code for using UILocalNotification
UILocalNotification* localNotification = [[UILocalNotificationalloc] init];
localNotification.fireDate = [NSDate dateWithTimeIntervalSinceNow:7200];
localNotification.alertBody = @"Your alert message";
localNotification.timeZone = [NSTimeZone defaultTimeZone];
[[UIApplication sharedApplication] scheduleLocalNotification:localNotification];
Upvotes: 2
Reputation: 134
If you want to schedule a notification for every 2 hours you have to schedule 12 notifications, 2 hours apart and have them repeated daily. This will allow you to schedule notifications every 2 hours to repeat indefinitely without exceeding the number of notifications you can set.
Upvotes: 1