ios - Is there any way to create hourly RecurrenceRule? -
i have ekevent
occurs every 4 hours, , want create single recurring event.
unfortunately available frequencies in ekrecurrencerule
class daily, weekly, monthly, , yearly.
how can set hourly frequency ekrecurrencerule
object ?
unfortunately there no way make hourly events using ekrecurrencerule
objects, can still write method same.
func createhourlyrecurringevent(eventtitle: string, startdate: nsdate, enddate: nsdate, endreccurencedate: nsdate, allday : bool, recurrencesecondsinterval: double, alarms: [ekalarm]? , traveltime: int?) { var eventstartdate = startdate var eventenddate = enddate while eventstartdate.earlierdate(endreccurencedate) != endreccurencedate { let event = ekevent(eventstore: self.eventstore) event.title = eventtitle event.startdate = eventstartdate event.enddate = eventenddate event.allday = allday event.alarms = alarms event.calendar = eventstore.defaultcalendarfornewevents if let traveltime = traveltime { event.setvalue(traveltime, forkey: "traveltime") } { try eventstore.saveevent(event, span: .thisevent) print("hourly event created)") print("start date: \(formatter.stringfromdate(event.startdate)") print("end date: \(formatter.stringfromdate(event.enddate))") } catch { print("event failed save") } eventstartdate = nsdate(timeinterval: recurrencesecondsinterval, sincedate: event.startdate) eventenddate = nsdate(timeinterval: recurrencesecondsinterval, sincedate: event.enddate) } }
this code sits inside schedule
class. after creating instance of schedule can create hourly recurring event this:
let startdate = nsdate() let enddate = nsdate(timeinterval: 10800, sincedate: startdate) let oneweekinseconds = 604800.0 let endrecurrencedate = nsdate(timeinterval: oneweekinseconds, sincedate: nsdate()) let fourhours = 14400.0 schedule!.createhourlyrecurringevent("testing", startdate: startdate, enddate: enddate, endreccurencedate: endrecurrencedate, allday: false, recurrencesecondsinterval: fourhours, alarms: nil, traveltime: nil)
deleting individual events simple, so:
func deleteevent(eventtoremove: ekevent) -> bool { var successful = false { print("deleting single event") try self.eventstore.removeevent(eventtoremove, span: .thisevent) successful = true } catch { print("bad things happened") } return successful }
i've yet find way batch delete events because have different unique ids. ill update post when find way.
Comments
Post a Comment