本地通知-快速重复间隔3 [英] Local notifications - repeat Interval in swift 3
本文介绍了本地通知-快速重复间隔3的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想每周重复一次本地通知,在iOS10之前有 repeatInterval
,但是我找不到适合在iOS10中重复通知的任何内容. TimeTrigger
和 calendarTrigger
都重复为true或false,我可以在哪里应用每周一次,每天一次,每月一次的重复.
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.
谢谢.
推荐答案
尝试一下.
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)")
}
}
}
这篇关于本地通知-快速重复间隔3的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文