使用以下代码处理警报应用并尝试每周重复警报:

if repeatWeekly {
    let triggerWeekly = (Calendar.current as NSCalendar).components([.weekOfYear, .hour, .minute, .second], from: currentDateTime)
    trigger = UNCalendarNotificationTrigger(dateMatching: triggerWeekly, repeats: true)
} else {
    let triggerDaily = (Calendar.current as NSCalendar).components([.hour,.minute,.second,], from: currentDateTime)
    trigger = UNCalendarNotificationTrigger(dateMatching: triggerDaily, repeats: false)
}

在iOS9中使用 UILocalNotification 它可以正常使用以下代码:

let localNotification = UILocalNotification()
localNotification.repeatInterval = NSCalendar.Unit.weekOfYear

但在iOS10中使用 UNUserNotification 重复本地通知无法正常工作,它只会重复1周而且从未出现在下周 .

例如,如果当前日期时间为“2017年9月1日”,则将在“2017年9月8日”重复通知,但不会在9月15日,9月22日左右重复通知 .

谢谢