0

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

4

1 回答 1

0

在句子

安排在晚上 10:43 触发通知,然后在每小时 43 分钟后每小时重复一次

只有“从那时起”是不可能的。

您可以创建UNNotificationRequestwith which 将在每小时 XX:43:00 开始触发,因为请求将添加UNCalendarNotificationTrigger到.DateComponents(minute: 43, second: 00)UNUserNotificationCenter

剩下的唯一问题是在晚上 9:44 到晚上 10:42 期间添加它,这样它就不会太早开始发射。我没有看到实现这一点的漂亮方法,但如果推送通知对您来说足够好 - 它可能是一个触发器,会将请求添加到通知中心。

于 2017-04-02T12:15:55.143 回答