Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

EKCADErrorDomain using calendarWithIdentifier

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.

like image 457
whtman Avatar asked Sep 22 '14 12:09

whtman


2 Answers

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....

}
like image 108
iamdavidlam Avatar answered Sep 24 '22 09:09

iamdavidlam


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 })
like image 30
Aaron Brager Avatar answered Sep 26 '22 09:09

Aaron Brager