2

I'm just trying to configure a local notification to trigger not only at a time, but also specific days of the week repeatedly for iOS 10, Xcode 8.3.

var notificationTimeComponents = DateComponents()
    
    notificationTimeComponents.timeZone = TimeZone.current
    notificationTimeComponents.hour = 10
    notificationTimeComponents.minute = 0
    notificationTimeComponents.weekday = 5
    notificationTimeComponents.weekday = 1 // <--- no good

let notificationTrigger = UNCalendarNotificationTrigger(dateMatching: notificationTimeComponents, repeats: true)
        
let notificationRequest = UNNotificationRequest(identifier: "Notification", content: notificationContent, trigger: notificationTrigger)
        
center.add(notificationRequest) { (error: Error?) in
    if let theError = error {
        print(theError.localizedDescription)
    }
}

In the documentation for DateComponents it says:

var day: Int? A day or count of days.

var weekday: Int? A weekday or count of weekdays.

It does work with just one weekday component but I'd like many. I'm not sure how to write the 'count of weekdays' in Xcode. Do I have to create a notification for each day separately?

Thank you

Community
  • 1
  • 1
shearos
  • 131
  • 1
  • 7

0 Answers0