【发布时间】:2019-02-07 11:22:52
【问题描述】:
基本上,我需要一个应用程序,该应用程序每隔星期一运行一次通知。我所拥有的是一个每个星期一运行通知的应用程序。有没有办法设置它,以便在收到第一个通知时,应用程序将开始一个两周的时间间隔,它将再次运行通知,并让它重复?例如,如果我有一个名为“week”的变量,并且每隔一周让它在“1”和“2”之间交替,我如何将它标记到通知的触发器?
func notification(hour: Int, minute: Int, weekday: Int, text: String){
let content = UNMutableNotificationContent()
content.title = "Example"
content.body = text
content.sound = UNNotificationSound.default()
let trigger = UNCalendarNotificationTrigger(dateMatching: DateComponents(hour: hour, minute: minute, weekday: weekday), repeats: true)
let request = UNNotificationRequest(identifier: text, content: content, trigger: trigger)
UNUserNotificationCenter.current().add(request, withCompletionHandler: nil)
}
override func viewDidLoad() {
super.viewDidLoad()
notification(hour: 12, minute: 0, weekday: 2, text: "Test")
}
【问题讨论】:
标签: ios swift usernotifications