【问题标题】:Local notifications - repeat Interval in swift 3本地通知 - 在 swift 3 中重复间隔
【发布时间】:2017-01-23 06:08:57
【问题描述】:

我想每周重复本地通知,在 iOS10 之前有 repeatInterval,但我无法在 iOS10 中找到适合重复通知的任何内容。 TimeTriggercalendarTrigger 都有重复为真或假,我在哪里可以应用重复为每周、每天、每月。

谢谢。

【问题讨论】:

    标签: ios swift swift3 ios10 localnotification


    【解决方案1】:

    试试这个。

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2023-04-02
      • 1970-01-01
      • 1970-01-01
      • 2017-12-17
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多