Pritam Salunkhe
Pritam Salunkhe

Reputation: 97

Schedule Notification with specified date

I want to implement scheduled notification(in iOS 10) using UNTimeIntervalNotificationTrigger or UNCalendarNotificationTrigger with repeat parameter as true for 2-3 consecutive days. Later on I can update or delete notification for upcoming days. e.g I scheduled notification on 13 Nov 2017 and I wanted to repeat this till 17 Nov 2017 at 10AM in morning and on 15 Nov 2017 I wanted to change the schedule time of notification for next 2days i.e (16 Nov and 17 Nov).

So can you please suggest me what are the alternatives or how this can be achieved?

Upvotes: 1

Views: 618

Answers (1)

Retterdesdialogs
Retterdesdialogs

Reputation: 3210

I think you can use a trigger for that.

let trigger = UNCalendarNotificationTrigger(dateMatching: dateComponents, repeats: true)

To create the dateComponents to match your needs you have to do for example:

// Matching specific minute and hour
let unitFlags = Set<Calendar.Component>([.hour, .minute])
dateComponents = NSCalendar.current.dateComponents(unitFlags, from: givenDate)

// Matching specific weekday, hour and minute
let unitFlags = Set<Calendar.Component>([.weekday, .hour, .minute])
dateComponents = NSCalendar.current.dateComponents(unitFlags, from: givenDate)

// Matching specific day, hour and minute
let unitFlags = Set<Calendar.Component>([.day, .hour, .minute])
dateComponents = NSCalendar.current.dateComponents(unitFlags, from: givenDate)

Upvotes: 3

Related Questions