iOS 10:如何在特定日期触发后重复本地通知?

时间:2017-01-21 04:38:10

标签: ios swift

我想在特定日期创建本地通知,然后在本地通知被解雇后每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)

另一个问题:如何设置多个警报以达到相同的效果?

示例:

闹1:1月21日上午8:30 - >每30秒重复一次

闹2:2017年1月22日上午8:32 - >每30秒重复一次 ... 等等。

这样做的最佳策略是什么?

1 个答案:

答案 0 :(得分:0)

我认为您需要设置两个function seekToTime(ts) { // try and avoid pauses after seeking video_element.pause(); video_element.currentTime = ts; // if this is far enough away from current, it implies a "play" call as well...oddly. I mean seriously that is junk. // however if it close enough, then we need to call play manually // some shenanigans to try and work around this: var timer = setInterval(function() { if (video_element.paused && video_element.readyState ==4 || !video_element.paused) { video_element.play(); clearInterval(timer); } }, 50); } 。我假设你想在用户没有回复时每30秒重复一次。

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

当用户回复第一个通知时,您可以删除第二个repeat: true

到目前为止,还没有一个 UNCalendarNotificationTrigger允许在不同内部重复,而无需用户回复通知。