iOS 10:在特定日期触发后如何重复本地通知?
我想在特定日期创建一个本地通知,然后在本地通知被触发后每30秒重复一次。这是我的密码:iOS 10:在特定日期触发后如何重复本地通知?,ios,swift,Ios,Swift,我想在特定日期创建一个本地通知,然后在本地通知被触发后每30秒重复一次。这是我的密码: let calendar = Calendar(identifier: .gregorian) let components = calendar.dateComponents(in: .current, from: date) let newComponents = DateComponents(calendar: calendar, timeZone: .current, month: component
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)
另一个问题:如何设置多个警报以实现相同的结果
例如:
报警1:2017年1月21日上午8:30->每30秒重复一次
报警2:2017年1月22日上午8:32->每30秒重复一次
...
等等
执行此操作的最佳策略是什么?我认为您需要设置两个
UNCalendarNotificationTrigger
。我假设当用户没有响应时,您希望每30秒重复一次
一个在2017年8:30:00时的Alarm1:1/21@。并在2017年1月21日8:30:30添加第二个UNCalendarNotificationTrigger
,使用repeat:true
当用户响应第一个通知时,可以删除第二个UNCalendarNotificationTrigger
到目前为止,还没有一个UserNotificationTrigger
允许在不同的内部位置重复,而用户不响应通知。根据UNCalendarNotificationTrigger(dateMatching:newComponents,repeats:true)
可能有助于每天8:30重复。不是每天早上8:30后的30秒。你回答了我的部分问题。我想要的是类似于Alarmify的东西,一旦警报在早上8:30触发,它就会一直重复,直到用户停止警报。