"Another instance of this event occurs on this date" when updating event on iOS
steven-sh opened this issue · 3 comments
Environment: iOS 12, connected to my calendar via an Exchange Legacy Connection
I've been having issues updating recurring events in some cases on iOS. Eventually I've discovered that certain properties some events are read-only on calendars that are otherwise writeable (I think this is because the events are 'owned' by another calendar. In my case I only seem to be able to update the event availability.
Stepping through the buildAndSaveEvent method native code it looks like attempts to set some properties of the calendar event (e.g. the start and end date) are ignored by EKEvent. Since the method just gets the event by calling calendarItemWithIdentifier and then modifying the start and end dates, this means that I either get the aforementioned error, or the first event in the series is edited.
I think instead of calling calendarItemWithIdentifier we're supposed to be fetching the correct event in the series using a predicate as is done in the removeEvent method.
Replacing the call to calendarItemWithIdentifier:eventId in buildAndSaveEvent with the below seems to fix it:
NSDate *exceptionDate = [RCTConvert NSDate:options[@"exceptionDate"]];
if(exceptionDate) {
NSPredicate *predicate = [self.eventStore predicateForEventsWithStartDate:exceptionDate
endDate:endDate
calendars:nil];
NSArray *calendarEvents = [self.eventStore eventsMatchingPredicate:predicate];
for (EKEvent *event in calendarEvents) {
if ([event.calendarItemIdentifier isEqualToString:eventId] && [event.startDate isEqualToDate:exceptionDate]) {
calendarEvent = event;
break;
}
}
}
else {
calendarEvent = (EKEvent *)[self.eventStore calendarItemWithIdentifier:eventId];
}
I'd be happy to make a PR but I'm completely new to Objective C and iOS native APIs so I'd appreciate some advice on whether or not this is the correct fix first.
Hi, I am totally unconfortable with iOS (or Android) natives APIs but your logic seems good. @wmcmahan should be able to validate this :)
Thanks @steven-sh - I think this may indeed be a bug. It's my understanding that calendarItemWithIdentifier with only get the first event in the occurrence, which explains why only your first event is getting updated. Sorry for the delay, but you are more than welcome to submit a PR. I will look into this more.