Forum Archive

Calendar event - recurrences and alarms

brumm

Who can help me with calendar event recurrences and alarms? I'd like to read and write EKRecurrenceRules and EKAlarms. Sorry still struggling with Objective-C.

That is what I got so far.

edit:
two examples from an event output:

recurrence = EKRecurrenceRule <0x10eee8160> RRULE FREQ=YEARLY;INTERVAL=1;COUNT=5;

alarms = (
"EKAlarm <0x109123e50> {triggerInterval = -300.000000}",
"EKAlarm <0x108d85720> {triggerInterval = -86400.000000}"
);

cvp

@brumm little help about

Code to get the alarms timers in seconds and code to add an alarm to an event

alarms = event.alarms # list of objects EKAlarm
for alarm in event.alarms:
    print(int(alarm.relativeOffset()/60))

# add non zero alarm
al = 900 # in seconds
alarm = ObjCClass('EKAlarm').alarmWithRelativeOffset_(al)
event.addAlarm_(alarm)
cvp

@brumm same kind of process, but more complex, for recurrence rules
see here

brumm

Great, thank you. I will try to write the recurrences part.

cvp

@brumm I forgot to say that you can define an alarm with:
A negative delay for "before the event begin"
A positive delay for "after the event begin". This is useful if you want to be warned some time before the end of the event. This is not possible via the standard iOS Calendar app but can be done on iMac. So you have the possibility now on your iDevice.

cvp

@brumm try this

recurrencerule = ObjCClass('EKRecurrenceRule').alloc()

# one way to init it
# frequency: 0=dayly, ...see https://developer.apple.com/documentation/eventkit/ekrecurrencefrequency?language=objc
recurrencerule.initRecurrenceWithFrequency_interval_end_(0,1,None)

# other methods allow to set attributes of recurrence rule
# print(dir(recurrencerule))
# setDaysOfTheMonth_
# setDaysOfTheWeek_
# setDaysOfTheYear_
# setEndDate_
# setFirstDayOfTheWeek_
# setFrequency_
# setInterval_
# setMonthsOfTheYear_
event.addRecurrenceRule_(recurrencerule)        

if event.hasRecurrenceRules():
    but = console.alert('Event is recurrent','modify this instance only?','Yes','No',hide_cancel_button=True)
    if but == 1:
        span = 0 # only this instance
    else:
        span = 1 # all instances
else:
    span = 0 # only this instance
# store modified event in calendar
store.saveEvent_span_error_(event,span,None) 
brumm

Thanks a lot!