1
我想每週重複本地通知,在iOS10之前有repeatInterval
,但我無法找到任何適合在iOS10中重複通知的內容。 TimeTrigger
和calendarTrigger
都重複爲真或假,我可以在哪裏申請重複每週,每天,每月。本地通知 - 在swift中重複間隔3
謝謝。
我想每週重複本地通知,在iOS10之前有repeatInterval
,但我無法找到任何適合在iOS10中重複通知的內容。 TimeTrigger
和calendarTrigger
都重複爲真或假,我可以在哪裏申請重複每週,每天,每月。本地通知 - 在swift中重複間隔3
謝謝。
試試這個。
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)")
}
}
}