Hourly repeating notification.

Somebody help me please. I try to set specific time for notification, it works nice, but if you need a little beat more functional this is where difficulties appear. I'd like to give opportunities for repeat, example every hour. I know that UNCalendarNotificationTriger has a repeat value, but when you set repeat on true it remember date component, exp - .minute, and then just repeating notification every time when that minute comes! I'm looking for solution for set notification at special time(exp: 5:00 pm), and then repeating this notification every hour(6, 7, 8, 9 pm)

Maybe it's so easy but looks like I feel stuck 😕

Answered by Engineer in 810093022

The functionality you are looking for is not available automatically with the current APIs.

What you can do is set the primary notification, and then add the secondary notifications separately at every hour after the primary in a loop.

The system allows up to 64 simultaneous notifications to be scheduled, so that is possibly enough for most use cases.


Argun Tekant /  DTS Engineer / Core Technologies

Create a UNCalendarNotificationTrigger object when you want to schedule the delivery of a local notification at the date and time you specify. You use an NSDateComponents object to specify only the time values that you want the system to use to determine the matching date and time.

Listing 1 creates a trigger that delivers its notification every morning at 8:30. The repeating behavior is achieved by specifying true for the repeats parameter when creating the trigger.

Listing 1. Creating a trigger that repeats at a specific time

var date = DateComponents()
date.hour = 8
date.minute = 30 
let trigger = UNCalendarNotificationTrigger(dateMatching: date, repeats: true)

Have you tried the sample code? Setting the hour and minute properties at the same time may help.


WindowsMEMZ @ Darock Studio
let myEmail = "memz" + "1" + "@" + "darock.top"

Accepted Answer

The functionality you are looking for is not available automatically with the current APIs.

What you can do is set the primary notification, and then add the secondary notifications separately at every hour after the primary in a loop.

The system allows up to 64 simultaneous notifications to be scheduled, so that is possibly enough for most use cases.


Argun Tekant /  DTS Engineer / Core Technologies

Hourly repeating notification.
 
 
Q