简体   繁体   中英

iOS 10: How to repeat local notification once fired on particular date?

I want to create a local notification on a specific date and then repeat every 30 seconds AFTER that local notification gets fired off. Here's my code:

let calendar = Calendar(identifier: .gregorian)
let components = calendar.dateComponents(in: .current, from: date)
let newComponents = DateComponents(calendar: calendar, timeZone: .current, month: components.month, day: components.day, hour: components.hour, minute: components.minute)
let trigger = UNCalendarNotificationTrigger(dateMatching: newComponents, repeats: false)
let request = UNNotificationRequest(identifier: ID, content: content, trigger: trigger)

Another problem: How do I set up multiple alarms to accomplish same result?

Example:

Alarm1: 1/21/2017 @ 8:30am -> repeats every 30 seconds

Alarm2: 1/22/2017 @ 8:32am -> repeats every 30 seconds ... so on.

What's the best strategy to do this?

I think you would need to setup two UNCalendarNotificationTrigger . I am assuming you want to repeat every 30 second when user does not response.

One at Alarm1: 1/21/2017 @ 8:30:00 that with repeat: false . And add a 2nd UNCalendarNotificationTrigger at 1/21/2017 @ 8:30:30 with repeat: true .

You could remove the 2nd UNCalendarNotificationTrigger when user response to the first notification.

So far, there isn't one UserNotificationTrigger that allow repeat at different internal without user responding to the notification.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM