Create weekly swift ios local notifications

Multi tool use
Create weekly swift ios local notifications
I can create daily notifications but not weekly ones using swift 3 ios 10 User Notifications framework. Daily works fine but when I add in the .weekday parameter it doesn't send me a notification.
The code is:
for i in 1 ... 7
{
let center = UNUserNotificationCenter.current();
let content = UNMutableNotificationContent();
content.title = "Title";
content.body = "content";
content.sound = UNNotificationSound.default();
var dateComponents = DateComponents();
dateComponents.weekday = i;
// hours is 00 to 11 in string format
if (daynight == "am")
{
dateComponents.hour = Int(hours);
}
else
{
dateComponents.hour = Int(hours)! + 12;
}
// mins is 00 to 59 in string format
dateComponents.minute = Int(mins);
dateComponents.second = 0;
let date = Calendar.current.date(from: dateComponents);
// tiriggerDaily works without weekday for daily but adding weekday doesn't make it weekly
let triggerDaily = Calendar.current.dateComponents([.weekday, .hour, .minute, .second], from: date!);
let trigger = UNCalendarNotificationTrigger(dateMatching: triggerDaily, repeats: true);
let identifier = // a uuid;
let request = UNNotificationRequest(identifier: identifier, content: content, trigger: trigger);
center.add(request, withCompletionHandler:
{
(error) in
if let error = error
{
// Error happened
print("Error: ");
print(error);
}
});
Need to get code to figure out weekly. Used this as guidance: https://useyourloaf.com/blog/local-notifications-with-ios-10/
An example of what I want is this:
A user selects Monday, 11:25pm and it is a Monday at 11:23pm.
Then the user should get a notification in two minutes plus one the following week and so on.
Some other notes/questions:
1. Do you have to wait a week for weekly notifications to start? Like in the example above will it start the following week?
Just a thought since I can't get this working right yet.
Not a duplicate i want weekly notifications not just any and can do daily ones
– cdub
Jul 2 at 5:43
Can you please elaborate more? do you want to add notification daily which will repeat on same day next week? or just a single notification weekly? Example with values would be more clear
– Van
Jul 2 at 6:02
I want a user to select a say Monday at 11:01pm and then the notification will repeat every monday at 11:01pm going forward. The user can select whatever date they want. (Something like this: stackoverflow.com/questions/45061324/…)
– cdub
Jul 2 at 6:09
By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.
Possible Duplicate of stackoverflow.com/questions/6047117/…
– Karthick Ramesh
Jul 2 at 5:41