OGeek|极客世界-中国程序员成长平台

标题: iOS 10 : How to repeat local notification once fired on particular date? [打印本页]

作者: 菜鸟教程小白    时间: 2022-12-11 18:39
标题: iOS 10 : How to repeat local notification once fired on particular date?

我想在特定日期创建本地通知,然后在本地通知被触发后每 30 秒重复一次。这是我的代码:

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)

另一个问题:如何设置多个警报来完成相同的结果?

例子:

Alarm1:1/21/2017 @ 8:30am -> 每 30 秒重复一次

Alarm2:1/22/2017 @ 8:32am -> 每 30 秒重复一次 ... 以此类推。

最好的策略是什么?



Best Answer-推荐答案


我认为您需要设置两个 UNCalendarNotificationTrigger。我假设您想在用户没有响应时每 30 秒重复一次。

一个在 Alarm1: 1/21/2017 @ 8:30:00repeat: false。并使用 repeat: true1/21/2017 @ 8:30:30 添加第二个 UNCalendarNotificationTrigger

当用户响应第一个通知时,您可以删除第二个 UNCalendarNotificationTrigger

到目前为止,没有一个 UserNotificationTrigger允许在不同的内部重复而不用户响应通知。

关于iOS 10 : How to repeat local notification once fired on particular date?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41775794/






欢迎光临 OGeek|极客世界-中国程序员成长平台 (http://ogeek.cn/) Powered by Discuz! X3.4