I'm building a calendar application, and have occasionally been running into a strange error when trying to save certain events. I haven't yet been able to reliably produce an event that replicates the issue, but I've been fortunate (if you can call it that) to have run into the bug again.
The issue is that when I save certain events, they refuse to save their recurrence rules. Most events save completely fine, and never have a problem.
I've included my debug output below. The first section, EVENT, describes the event object at the moment it is opened for editing. The second section, EVENT TO BE SAVED, describes the event object just before it is to be saved. The final section, EVENT SAVING ERROR, describes the error set by the EKEventStore saveEvent:span:commit:error:
method.
Any help would be much appreciated.
2013-12-23 11:47:23.641 planner[4360:60b] EVENT: EKEvent <0x1554d5d0>
{
EKEvent <0x1554d5d0>
{ title = Test repeat m;
location = ;
calendar = EKCalendar <0x1564cfc0> {title = Calendar; type = Local; allowsModify = YES; color = #CC73E1;};
alarms = (null);
URL = (null);
lastModified = 2013-12-23 17:31:29 +0000;
timeZone = America/Chicago (CST) offset -21600
};
location = ;
startDate = 2013-12-23 07:00:00 +0000;
endDate = 2013-12-23 08:00:00 +0000;
allDay = 0;
floating = 0;
recurrence = (null);
attendees = (null)
};
2013-12-23 11:47:32.480 planner[4360:60b] EVENT TO BE SAVED: EKEvent <0x1554d5d0>
{
EKEvent <0x1554d5d0>
{ title = Test repeat m;
location = ;
calendar = EKCalendar <0x1564cfc0> {title = Calendar; type = Local; allowsModify = YES; color = #CC73E1;};
alarms = (null);
URL = (null);
lastModified = 2013-12-23 17:31:29 +0000;
timeZone = America/Chicago (CST) offset -21600
};
location = ;
startDate = 2013-12-23 07:00:00 +0000;
endDate = 2013-12-23 08:00:00 +0000;
allDay = 0;
floating = 0;
recurrence = EKRecurrenceRule <0x155a3d10> RRULE FREQ=DAILY;INTERVAL=1;
attendees = (null)
};
2013-12-23 11:47:32.492 planner[4360:60b] EVENT SAVING ERROR: Error Domain=EKErrorDomain Code=28 "The repeat field cannot be changed." UserInfo=0x155826a0 {NSLocalizedDescription=The repeat field cannot be changed.}
AHA! I've finally figured this out! If a repeating event is saved with the span EKSpanThisEvent
, it becomes "detached." This can be checked by calling [event isDetached]
. We are not allowed to save recurrence rules on detached events.
The solution I used for my application is to hide the controls for setting recurrence rules when the user is editing a detached event. This seems to be the same solution that Apple uses in the default calendar app.