I can set a notification in a time interval but I don\'t know how make it in a specific time and date, I try this but don\'t work
let center = UNUserNotific
You're almost there. Not much left for you to do.
What you are missing is as follow:
weekday
to your date components, 1
is for Sunday so in your case you will need to set it to 2
for the Monday notification and 6
for your Friday notificationrepeats
to true
in your UNCalendarNotificationTrigger
.Here is a example.
// Create date components that will match each Monday at 15:00
var dateComponents = DateComponents()
dateComponents.hour = 15
dateComponents.minute = 0
dateComponents.weekday = 2 // Monday
// Create a calendar trigger for our date compontents that will repeat
let trigger = UNCalendarNotificationTrigger(dateMatching: dateComponents,
repeats: true)
// Create the content for our notification
let content = UNMutableNotificationContent()
content.title = "Foobar"
content.body = "You will see this notification each monday at 15:00"
// Create the actual notification
let request = UNNotificationRequest(identifier: "foo",
content: content,
trigger: trigger)
// Add our notification to the notification center
UNUserNotificationCenter.current().add(request)