iOS Notification Trigger: fortnightly and/or quarterly
I can’t seem to find any Apple Documentation for this exact scenario, and I’ve tried various ways to do this and I keep coming up empty.
I would like to schedule a repeating notification (
iOS 10+ so
UNCalendarNotificationTrigger or equivalent).
These are Local Notifications not Push Notifications.
Schedule notifications that repeat:
- once a fortnight (e.g., every second Tuesday)
- once a quarter (e.g., 1st of every 3 months)
My Current Approach:
These triggers work well, and are simple to implement (Running the code in a Swift Playground).
// Every day at 12pm var daily = DateComponents() daily.hour = 12 let dailyTrigger = UNCalendarNotificationTrigger(dateMatching: daily, repeats: true) dailyTrigger.nextTriggerDate() // "Jan 4, 2017, 12:00 PM" // Every Tuesday at 12pm var weekly = DateComponents() weekly.hour = 12 weekly.weekday = 3 let weeklyTrigger = UNCalendarNotificationTrigger(dateMatching: weekly, repeats: true) weeklyTrigger.nextTriggerDate() // "Jan 10, 2017, 12:00 PM" // The 1st of every month at 12pm var monthly = DateComponents() monthly.hour = 12 monthly.day = 1 let monthlyTrigger = UNCalendarNotificationTrigger(dateMatching: monthly, repeats: true) monthlyTrigger.nextTriggerDate() // "Feb 1, 2017, 12:00 PM" // Every 1st of February at 12pm var yearly = DateComponents() yearly.hour = 12 yearly.day = 1 yearly.month = 2 let yearlyTrigger = UNCalendarNotificationTrigger(dateMatching: yearly, repeats: true) yearlyTrigger.nextTriggerDate() // "Feb 1, 2017, 12:00 PM"
I can’t seem to get a
quarterly trigger to function correctly.
// Every second Tuesday at 12pm // ... There is no "date.fortnight", is this possible? // The 1st of every quarter at 12pm var quarterly = DateComponents() quarterly.hour = 12 quarterly.day = 4 // Values: 1, 2, 3 or 4 all produce the same "nextTriggerDate" - why? quarterly.quarter = 4 let quarterlyTrigger = UNCalendarNotificationTrigger(dateMatching: quarterly, repeats: true) quarterlyTrigger.nextTriggerDate()
So, to be clear, my questions are:
- Is it possible to get a notification that repeats every fortnight?
- How do we get a trigger for once a quarter?
DateComponents() has a
quarter unit, I assume that a
quarterly trigger is possible. For the fortnightly reminder however, I’m not even sure if this is possible…
Any insight would be appreciated!
- finding out days remain from array of dates
- Converting a gregorian date string to Islamic date gives correct & incorrect results
- How do I find the beginning of the week from an NSDate?
- How to get the number of weeks from given year
- iOS Swift converting calendar component int month to medium style string month
- How can i get all calendar and its events from iphone app?
Solutions Collect From Internet About “iOS Notification Trigger: fortnightly and/or quarterly”
I didn’t see any direct option to trigger fortnight notification.Suggestion from my end.
1) Is it possible to get a notification that repeats every fortnight?
I am proposing two options:
Can we use
UNTimeIntervalNotificationTriggerto repeat the notification with a time interval of two weeks time? Example below
let timeInterValFor2Weeks = 1190507.790425003 let intervalTrigger = UNTimeIntervalNotificationTrigger(timeInterval: timeInterValFor2Weeks, repeats: true)//"Jan 3, 2017, 5:24 PM" intervalTrigger.nextTriggerDate() //"Jan 17, 2017, 12:05 PM"
UNCalendarNotificationTriggertrigger, which should trigger first and third day of a month. For example it should fire notification in first Sunday and third Sunday of a month.
var fortnightPart1 = DateComponents() fortnightPart1.weekday = 1 //(Day..here Sunday) fortnightPart1.weekdayOrdinal = 2 //= n == (nth Day in the month...here 2nd Sunday in every month month) fortnightPart1.hour = 12 let fortnightTrigger = UNCalendarNotificationTrigger(dateMatching: fortnightPart1, repeats: true) fortnightPart1.nextTriggerDate()
2) How do we get a trigger for once a quarter?
If there is no direct option available, then I suggest the same solution as above.
- How to get back the UIButton border in iOS 7?
- Know the download progress for update an UIprogressView
- Xcode iOS Simulator: can I use the mouse as pretend Apple Pencil input (on iPad Pro), for testing?
- (Cocoa error 3840.)” (Invalid value around character 0.) AFNetworking
- Take a picture in iOS without UIImagePicker and without preview it
- Show time like a digital clock
- Searching NSArray of NSDictionary objects
- setKeepAliveTimeout iOS behavior, exceeded 15 wakes in 300 sec
- Swift String Interpolation displaying optional?
- Swift 4 – UIApplication.registerForRemoteNotifications() must be called from main thread only
- How to compile an objective c program under windows with independant MingW
- Build error when trying to override an initializer in Xcode 6.3 Beta 3
- Error “Call can throw, but is not marked with 'try' and the error is not handled”
- Adding cells to table view (UITableView) in XCode
- UIButton Changing Position