使用指定日期安排通知

时间:2017-11-13 16:28:27

标签: swift notifications ios10 localnotification unusernotificationcenter

我希望使用UNTimeIntervalNotificationTriggerUNCalendarNotificationTrigger以及repeat参数true连续2-3天实施预定通知(在iOS 10中)。稍后我可以更新或删除即将到来的日子的通知。例如,我在13 Nov 2017安排了通知,我希望在早上17 Nov 201710AM 15 Nov 2017重复这一过程,我希望更改接下来2天的通知时间表,即(16 Nov17 Nov)。

那么请您建议我有哪些替代方案或如何实现这一目标?

1 个答案:

答案 0 :(得分:3)

我认为你可以使用触发器。

let trigger = UNCalendarNotificationTrigger(dateMatching: dateComponents, repeats: true)

要创建dateComponents以满足您的需求,例如:

// Matching specific minute and hour
let unitFlags = Set<Calendar.Component>([.hour, .minute])
dateComponents = NSCalendar.current.dateComponents(unitFlags, from: givenDate)

// Matching specific weekday, hour and minute
let unitFlags = Set<Calendar.Component>([.weekday, .hour, .minute])
dateComponents = NSCalendar.current.dateComponents(unitFlags, from: givenDate)

// Matching specific day, hour and minute
let unitFlags = Set<Calendar.Component>([.day, .hour, .minute])
dateComponents = NSCalendar.current.dateComponents(unitFlags, from: givenDate)
相关问题