问题
I want to repeat local notification every week, before iOS10 there is repeatInterval
, but i am not able to find anything suitable to repeat notifications in iOS10.
TimeTrigger
and calendarTrigger
both have repeat as true or false, where can i apply repeat as weekly, daily, monthly.
Thanks.
回答1:
Try this.
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)")
}
}
}
来源:https://stackoverflow.com/questions/41800189/local-notifications-repeat-interval-in-swift-3