0

The following code works for non-recurring events, changes to startDate and endDate are saved just fine.

BOOL success = [theEventStore saveEvent:event
                                   span:EKSpanFutureEvents
                                 commit:YES error:&error];

But whenever I try to edit an event that has recurranceRules, it returns with success == YES, but nothing is saved, and any changes to startDate/endDate or the recurranceRules are reverted back to the original values. (Using span:EKSpanThisEvent works, but this is of course not what I want to do. Also, the code works on iOS, but not on OSX.)

2 Answers 2

1

eventWithIdentifier returns the first occurrence of a recurring event. When you change something on this event with EKSpanFutureEvents, you will change all occurrences. eventsMatchingPredicate returns every event occurrence that matches your predicate. EKSpanFutureEvents will change each occurrence from the certain occurrence you used. If a event is detached it doesn't matter, if you take EKSpanThisEvent or EKSpanFutureEvents. I don't get what your code is supposed to do.

2
  • According to the tests I've done, it works as you say on the iOS. But on the Mac, using eventsMatchingPredicate doesn't work, it doesn't save the changes. The workaround I use is to pick up the original occurrence using eventWithIdentifier. But it's all a bit puzzling, so all clues on whats going on are welcome. May 26, 2013 at 14:07
  • I have no experience on Mac, sorry.
    – Thomas M
    May 27, 2013 at 8:30
0

I think I've found a solution, or at least a workaround. It seems that on Mac OS X when you modify recurrent events you should get them with eventWithIdentifier and not use the ones from eventsMatchingPredicate.

NSArray* events = [_eventStore eventsMatchingPredicate:predicate];
EKEvent* event = [events objectAtIndex:index];
EKEvent* original = [_eventStore eventWithIdentifier:event.eventIdentifier];
if (event.isDetached)
{
    … // modify detached event
    success = [_eventStore saveEvent:event
        span:EKSpanThisEvent
        commit:YES
        error:&error];
}
else if (!original.hasRecurrenceRules)
{
    … // modify non-recurrent event
    success = [_eventStore saveEvent:event
        span:EKSpanFutureEvents
        commit:YES
        error:&error];
}
else
{
    … // modify the original in a series of recurring events
    success = [_eventStore saveEvent:original
        span:EKSpanFutureEvents
        commit:YES
        error:&error];
}

I haven't found any good documentation on this, maybe it's a "bug" or just one of those peculiar behaviors of EventKit. In any case it seems that you need to take great care when modifying recurring events.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.