Volodymyr Hanas
Volodymyr Hanas

Reputation: 61

Repeating iOS Notification

Is there any way to schedule local notification which fires at specific date and the repeats every minute? Example: user receive first notification at 8:00 AM and then 8:01, 8:02...

Upvotes: 0

Views: 72

Answers (1)

LLIAJLbHOu
LLIAJLbHOu

Reputation: 1313

To schedule repeated notification you need date components in trigger initialization.

e.g.

let date = Date(timeIntervalSinceNow: 3600)
let triggerDaily = Calendar.current.dateComponents([.hour,.minute,.second], from: date)
let trigger = UNCalendarNotificationTrigger(dateMatching: triggerDaily, repeats: true)

trigger repeats notification daily

try to setup trigger using only .second in date components

let date = Date(timeIntervalSinceNow: 3600)
let triggerDaily = Calendar.current.dateComponents([.second], from: date)
let trigger = UNCalendarNotificationTrigger(dateMatching: triggerDaily, repeats: true)

Upvotes: 0

Related Questions