【发布时间】:2017-01-23 06:08:57
【问题描述】:
我想每周重复本地通知,在 iOS10 之前有 repeatInterval,但我无法在 iOS10 中找到适合重复通知的任何内容。
TimeTrigger 和 calendarTrigger 都有重复为真或假,我在哪里可以应用重复为每周、每天、每月。
谢谢。
【问题讨论】:
标签: ios swift swift3 ios10 localnotification
我想每周重复本地通知,在 iOS10 之前有 repeatInterval,但我无法在 iOS10 中找到适合重复通知的任何内容。
TimeTrigger 和 calendarTrigger 都有重复为真或假,我在哪里可以应用重复为每周、每天、每月。
谢谢。
【问题讨论】:
标签: ios swift swift3 ios10 localnotification
试试这个。
func scheduleNotification(at date: Date, body: String) {
let triggerWeekly = Calendar.current.dateComponents([.weekday,hour,.minute,.second,], from: date)
let trigger = UNCalendarNotificationTrigger(dateMatching: triggerWeekly, repeats: true)
let content = UNMutableNotificationContent()
content.title = "Dont Forget"
content.body = body
content.sound = UNNotificationSound.default()
//content.categoryIdentifier = "todoList"
let request = UNNotificationRequest(identifier: "textNotification", content: content, trigger: trigger)
UNUserNotificationCenter.current().delegate = self
//UNUserNotificationCenter.current().removeAllPendingNotificationRequests()
UNUserNotificationCenter.current().add(request) {(error) in
if let error = error {
print("Uh oh! We had an error: \(error)")
}
}
}
【讨论】: