12

In my iOS app i used to access calendar with the following method:

EKCalendar* cal = [eventStore calendarWithIdentifier:[calendarIDs objectAtIndex:i]];

permissions are asked to the user via:

eventStore requestAccessToEntityType:EKEntityTypeEvent completion:^(BOOL granted,NSError* error){}

now this works fine on iOS 7, but on iOS 8 i keep getting the following error every time the method calendarWithIdentfier is called:

Error getting shared calendar invitations for entity types 3 from daemon: 
Error Domain=EKCADErrorDomain Code=1013 
"The operation couldn’t be completed. (EKCADErrorDomain error 1013.)"

I can write\read the calendar with no problem, but i don't understand why this exception is raised. I have tried some method proposed here but none of them seems to working in this case.

whtman
  • 254
  • 3
  • 11

2 Answers2

10

I'm stumped on the same silly thing too.

I just looped over an array of calendars and match according to the identifier. It's not elegant, but it works and the average user probably have less than 10 calendars so...oh well..

here's my workaround in swift

func createEvent(){
    var event = EKEvent(eventStore: self.eventStore)
    var calendar : EKCalendar!
    let calendars : [EKCalendar] = self.eventStore.calendarsForEntityType(EKEntityTypeEvent) as [EKCalendar]

    for aCal in calendars
    {
        if(aCal.calendarIdentifier == self.calendarIdentifier)
        {
            calendar = aCal
            break
        }
    } ...continue to do stuff to events....

}
iamdavidlam
  • 404
  • 5
  • 10
  • I have the same problem described in the question, but don't get your answer. Can you explain why this error message displays? – Frank Martin Sep 24 '14 at 14:07
  • I have no idea why the error message is displayed. Hopefully I'd be enlightened too. But I do know that my solution worked for my case, and hopefully it'd work for yours too :) – iamdavidlam Sep 25 '14 at 04:34
  • i used your workaround and worked, no more error :) i mark your answer as correct, hope one day we will understand why the exception is raised – whtman Sep 26 '14 at 08:59
  • @whtman: Would you mind to share how you did change your code (before/after) ? – Frank Martin Sep 27 '14 at 14:40
  • Hi Frank, the method: [eventStore calendarWithIdentifier: someIdentifier] is the culprit what my snippet do is basically identify the calendar by it's identifier 'manually' rather than using a solution out of the box :) – iamdavidlam Sep 29 '14 at 01:06
  • @iamdavidlam: Thanks a lot for your explanation. Now I unterstand what you do and was able to fix my code! :-) – Frank Martin Sep 29 '14 at 08:35
  • 1
    Instead of looping over calendarIdentifiers: `for (NSString *storeCalID in storeCalIDs) { EKCalendar *aCal = [store calendarWithIdentifier:storeCalID]; [storeCals addObject:aCal]; } ` the fixed code loops over Calendars: `for (EKCalendar *aCal in [store calendarsForEntityType:EKEntityTypeEvent]) { if ([storeCalIDs containsObject:aCal.calendarIdentifier]) { [storeCals addObject:aCal]; } } ` – Frank Martin Sep 29 '14 at 08:46
  • 2
    Thanks, this was stumping me, too. A more concise way to write it: `let allCalendars : [EKCalendar] = self.eventStore.calendarsForEntityType(EKEntityTypeEvent) as [EKCalendar]` ` \ ` `let calendars = allCalendars.filter { $0.calendarIdentifier == self.calendarIdentifier }` – Brad G. Oct 17 '14 at 04:35
2

Swift 4.2

Instead of

let matchedCal = eventStore
    .calendar(withIdentifier: calendarIdentifier)

You can use:

let matchedCal = eventStore
    .calendars(for: .event)
    .first(where: { $0.calendarIdentifier == calendarIdentifier })
Aaron Brager
  • 65,323
  • 19
  • 161
  • 287