Reputation: 709
Has anyone been successful at scheduling a repeating hourly local notification with UNUserNotificationCenter without creating multiple request?
I need to be able to schedule hourly notifications to go off at a specific minute from which the first notification is set to go off. I am able to do this using the old UILocalNotification framework but I want to be able to take advantage of notification extensions, titles, subtitles etc that come along with the new notifications framework.
If it's not possible to schedule a single request that repeats hourly at a specific time, has anyone found a way to achieve this using multiple requests? And doing so without requiring the user to action against the first notification?
My other concern with scheduling multiple requests is that my app allows a user to create multiple reminders and I don't want to limit the user due to the 64 notification cap
Edit: My current use case is, it's 6:30am and I want to schedule a notification to trigger at 10:43 pm and from that point repeat hourly at 43 minutes past every hour. This is currently achievable with UILocalNotification using repeatInterval and setting the units to hour, so it will fire at that time and every hour after
Upvotes: 0
Views: 961
Reputation: 1469
In sentence
to schedule a notification to trigger at 10:43 pm and from that point repeat hourly at 43 minutes past every hour
only "from that point" is impossible.
You can create UNNotificationRequest
with UNCalendarNotificationTrigger
with DateComponents(minute: 43, second: 00)
which will start firing at XX:43:00 every hour since request will be added to UNUserNotificationCenter
.
The only problem left is to add it in period from 09:44pm to 10:42pm so it will not start firing too early. I don't see beautiful way to accomplish that, but if push notification is good enough for you - it can be a trigger that will add request to notification center.
Upvotes: 0