Question

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.}
Was it helpful?

Solution

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.

OTHER TIPS

I know that this original thread is old but I had come across a similar issue and wanted to add my perspective.

My steps to recreate are:

  1. create a new event with a recurrence rule
  2. update that event removing the recurrence rule
  3. update that save event again this time re-adding a recurrence rule

Upon the second update, the recurrence rule was not accepted just as Michael reported. After reading this post, I too found that the event had isDetached set to true.

Per SOP, the event was originally saved with EKSpan.futureEvents as it had a recurrence rule set.

However, also per SOP, the save without the recurrence rule used EKSpan.thisEvent. This is what caused the event to be detached (isDetached = true).

The solution is to save the event with EKSpan.futureEvents even though the update didn't have any recurrence rules.

From there, the standard logic of when to use .thisEvent or .futureEvents still holds.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top