繁体   English   中英

本地通知-快速重复间隔3

[英]Local notifications - repeat Interval in swift 3

我想每周重复一次本地通知,在iOS10之前有repeatInterval ,但是我找不到适合在iOS10中重复通知的任何内容。 TimeTriggercalendarTrigger都重复为true或false,我可以在哪里应用每周,每天,每月重复。

谢谢。

尝试这个。

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)")
      }
    }
  }

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM