Remove EKRecurrenceRuleMBS from an Event (EKEventMBS)

I create an event with:
var r as new EKEventMBS(EventStore)
var w as new EKRecurrenceRuleMBS(3,1)
r.[b]addRecurrenceRule/b

If I try to remove the RecurrenceRule, I got an error:
var r as new EKEventMBS(EventStore)
var w as new EKRecurrenceRuleMBS(3,1)
r.[b]removeRecurrenceRule/b

ERROR:
Failed to change event: Es ist nicht möglich, die Wiederholungsregel nur für ein Ereignis zu ändern. Sie muss auf die gesamte Reihe angewendet werden.

Failed to change event: It is not possible to change the repetition rule for one event only. It must be applied to the entire series.

Well I would expect you get the existing rule from the event you found and not create a new rule there to remove it.

Next try:
var r as new EKEventMBS(EventStore)
r.calendar = EventStore.calendarWithIdentifier(CurrentCalendarUUID)
r = EventStore.eventWithIdentifier(EventUUID)
for each w as EKRecurrenceRuleMBS in r.recurrenceRules
r.removeRecurrenceRule(w)
next

Same Error:
Failed to change event: It is not possible to change the repetition rule for one event only. It must be applied to the entire series.

First the first two lines there look unneeded. You create an event object and then throw it away in line 3.

Next the error message says you need to remove rule for whole series.

Did you get the first event of the series or one of the intermediate ones?

Sorry, but I don’t find anything on this in Apple’s documentation or forums.

1. Create a new event with EKRecurrenceRuleMBS(3,1, nil) while AutoRenewal ist set TRUE:
var r as new EKEventMBS(EventStore)
r.calendar = EventStore.calendarWithIdentifier(CalendarID)
r.title = EventTitle
r.notes = “just a test”
r.startDate = KterminDate
dim EndDate as new date(KterminDate)
EndDate.Minute = EndDate.Minute+KTerminDauer
r.endDate = EndDate
if AutoRenewal then
var w as new EKRecurrenceRuleMBS(3,1, nil)
r.addRecurrenceRule(w)
end if
var e as NSErrorMBS
if EventStore.saveEvent(r, eventstore.kSpanThisEvent, true, e) then
TerminUID = r.eventIdentifier
tfEventUUID.value = r.eventIdentifier
MsgBox “Event created”
else
MsgBox "Failed to create event: " + e.LocalizedDescription
end if

2. Select/find existing event with EventStore.eventWithIdentifier(EventUUID) and change it without EKRecurrenceRuleMBS while AutoRenewal is FALSE:
var r as new EKEventMBS(EventStore)
r.calendar = EventStore.calendarWithIdentifier(CalendarID)
r = EventStore.eventWithIdentifier(EventUUID)
r.title = EventTitle
r.notes = “Event changed”
r.startDate = KterminDate
var EndDate as new date(KterminDate)
EndDate.Minute = EndDate.Minute+KTerminDauer
r.endDate = EndDate
if AutoRenewal then
var w as new EKRecurrenceRuleMBS(3,1, nil)
r.addRecurrenceRule(w)
else
var w as new EKRecurrenceRuleMBS(3,1)
r.removeRecurrenceRule(w)
end if
var e as NSErrorMBS
if EventStore.saveEvent(r, eventstore.kSpanThisEvent, true, e) then
MsgBox “Event wurde gendert”
return true
else
MsgBox "Failed to change event: " + e.LocalizedDescription
return false
end if

And you got it to work?

No. It’s the same error:
Failed to change event: It is not possible to change the repetition rule for one event only. It must be applied to the entire series.

Here is the default calendar example from MBS plugins with some additional features and changes.

  1. request access to calendars
  2. select a calendar from the list
  3. de-activate checkbox for “Renew automatically” (annual repetition)
  4. let the field title empty
  5. add new event and check your calendar for the new event entry
  6. change title and end date and activate checkbox for “Renew automatically”
  7. click on change event
  8. check your calendar for the changed event entry

After you have created the new event:

New event in calendar

After you have change the event with “Renew automatically”

If you try to remove the “Renew automatically”

Download example project

Thanks. I tried it and I see the error.

A few notes:
The API only allows one RecurrenceRule, so calling addRecurrenceRule replaces the existing rule.

I see you do:

var r as new EKEventMBS(EventStore) r.calendar = EventStore.calendarWithIdentifier(CurrentCalendarUUID) r = EventStore.eventWithIdentifier(EventUUID)

But why do you make a new event, set the calendar and then throw the object away and lookup an event by it’s UUID instead?

Next please use EKRecurrenceRuleMBS.kRecurrenceFrequencyYearly Constant instead of passing value 3. The constants are there to make reading code easier.

The fix for the problem seems to be to pass kSpanFutureEvents for saveEvent call in ChangeEvent method.

Thank for this information. I use kRecurrenceFrequencyYearly and don’t use r.calendar = EventStore.calendarWithIdentifier(CurrentCalendarUUID) for an existing event.

Now I have found the error.
Wrong:
if EventStore.saveEvent(r, eventstore.kSpanThisEvent, true, e) then…

Right:
if EventStore.saveEvent(r, eventstore.kSpanFutureEvents, true, e) then…