Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Error getting shared calendar invitations for entity types 3, Xcode 6.1.1. EKCalender, EKSource, EKEventstore and Objective C

I am developing calendar app. I am trying to save EKEvent using assigned EKCalender. But when I try to run following code it gives me error. Please help

-(BOOL)createEventWithTitle:(NSString *)paramTitle startDate:(NSDate *)paramStartDate endDate:(NSDate *)paramEndDate inCalendar:(EKCalendar *)paramCalendar inEventStore:(EKEventStore *)paramStore notes:(NSString *)paramNotes 
        {
         BOOL result = NO;

        //paramCalendar = [self.eventStoreiReportShifts defaultCalendarForNewEvents];
            if (self.eventsAccessGranted) {
                NSArray *caledars = [self.eventStore calendarsForEntityType:EKEntityTypeEvent];
                self.selectedCalendarEventKitIdentifier = [[NSUserDefaults standardUserDefaults] objectForKey:@"eventkit_cal_identifiers_string"];
                for(EKCalendar *aCal in caledars){
                    if([aCal.calendarIdentifier isEqualToString:self.selectedCalendarEventKitIdentifier]){
                        paramCalendar = [self.eventStore calendarWithIdentifier:[[NSUserDefaults standardUserDefaults] objectForKey:@"eventkit_cal_identifiers_string"]];
                    }
                }
                for (EKSource *source in self.eventStore.sources) {
                    if (source.sourceType == EKSourceTypeCalDAV) {
                        paramCalendar.source = source;
                        break;
                    } else if(source.sourceType == EKSourceTypeLocal){
                        paramCalendar.source = source;
                        break;
                    }
                }

        }else{
            return NO;
        }

        /* If a calendar does not allow modification of its contents
         then we can not insert an event into it */
        if (paramCalendar.allowsContentModifications == NO) {
            NSLog (@ "\n\n The selected calendar does not allow modifications.");
            return NO;
        }
        /* Create an event */

        EKEvent * event = [EKEvent eventWithEventStore:paramStore];

        event.calendar = paramCalendar;
        /* Set the properties of the event such as its title,
         start date / time, end date / time, etc. */
        event.title = paramTitle;
        event.notes = paramNotes;
        event.startDate = paramStartDate;
        event.endDate = paramEndDate;
        /* Finally, save the event into the calendar */
        NSError * saveError = nil;
        result = [paramStore saveEvent:event
                                  span:EKSpanThisEvent
                                 error:&saveError];
        if (result == NO) {
            NSLog (@ "\n\n An error occurred = %@", saveError);
        }
        return result;
    }

above code gives following error

    CalendarCalculations[1668:45103] 
    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.)"

how can I get rid of it please?

like image 840
user2511630 Avatar asked Feb 01 '15 00:02

user2511630


3 Answers

I had the same problem in my app. I noticed the error occurs when calendarWithIdentifier method is called.

EKCalendar *selectedCalendar = [self.eventStore calendarWithIdentifier:selectedCalendarIdentifier];

I don't know exactly why it occurs but I guess it happens when you don't have any shared calendar in your device. Here is a link About shared iCloud calendars

I found the solution here and i fixed it in my app with next code snippet:

EKCalendar *selectedCalendar = [EKCalendar calendarForEntityType:EKEntityTypeEvent eventStore:self.eventStore];
NSString *selectedCalendarIdentifier = [[NSUserDefaults standardUserDefaults] objectForKey:@"selectedCalendarIdentifier"];

//instead of getting calendar by identifier
//get all calendars and check matching in the cycle
NSArray *allCalendars = [self.eventStore calendarsForEntityType:EKEntityTypeEvent];
for (EKCalendar *calendar in allCalendars) {
    if ([calendar.calendarIdentifier isEqualToString:selectedCalendarIdentifier]) {
        selectedCalendar = calendar;
        break;
    }
}

Off course it's not very good way but error disappeared. Hope it will help you ;)

like image 118
LembergSun Avatar answered Oct 24 '22 04:10

LembergSun


Another cause for this error is to use the bit mask EKEntityMaskEvent instead of the type EKEntityTypeEvent for the entity type parameter creating the calendar.

If you try to create the calendar such as:

EKCalendar *calendar = [EKCalendar calendarForEntityType:EKEntityMaskEvent eventStore:self.eventStore];

Then the calendar is well returned with an identifier, but the calendar seems not to be valid and it cannot be saved although no error is get. No event cannot be added to it. And the calendarWithIdentifier returns nil.

The right syntax is using EKEntityTypeEvent such as:

EKCalendar *calendar = [EKCalendar calendarForEntityType:EKEntityTypeEvent eventStore:self.eventStore];
like image 1
Lisarien Avatar answered Oct 24 '22 04:10

Lisarien


Old question but, for reference, I had this problem when I switched from working with Reminders to Calendar events. I forgot to change the entity type in all the places.

Specifically, I was loading the status of my permissions for EKEntityTypeReminder with

EKAuthorizationStatus authorizationStatus = [EKEventStore authorizationStatusForEntityType:EKEntityTypeReminder];

and latter asking the user permission for EKEntityTypeEvent with

[self.eventStore requestAccessToEntityType:EKEntityTypeEvent completion:^(BOOL granted, NSError *error) {
    if (error == nil) {
        // Store the returned granted value.
    } else {
        NSLog(@"%@", [error localizedDescription]);
    }
}];

So, the solution was to change the checking of status of my permissions to this:

EKAuthorizationStatus authorizationStatus = [EKEventStore authorizationStatusForEntityType:EKEntityTypeEvent];
like image 1
Rodrigo Pinto Avatar answered Oct 24 '22 04:10

Rodrigo Pinto