Robert
Robert

Reputation: 11

Can't retrieve EKCalendars from EKEventStore in iOS7

I've recently found out, that I do not receive any EKCalendar objects from EKEventStore in iOS7. In iOS 6.x.x there are no problems with same code snippet. When I'm trying to access defaultCalendarForNewEvents - I do receive a single EKCalendar object (as expected).

I do request access to entity type EKEntityTypeEvent.

The snippet:

__block NSMutableArray *calendarsArray = nil;

if ([self.eventsStore respondsToSelector:@selector(requestAccessToEntityType:completion:)]) {
    [self.eventsStore requestAccessToEntityType:EKEntityTypeEvent completion:^(BOOL granted, NSError *error) {
        if (granted) {
            EKAuthorizationStatus status = [EKEventStore authorizationStatusForEntityType:EKEntityTypeEvent];

            if (status == EKAuthorizationStatusAuthorized) {
                calendarsArray = [[NSMutableArray alloc] initWithArray:[self.eventsStore calendarsForEntityType:EKEntityMaskEvent]];
            }
        } else {
            UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Error!" message:@"You haven't granted access to calendars. Expected things are not going to happen." delegate:nil cancelButtonTitle:@"I understand" otherButtonTitles:nil];
            [alert show];
        }
    }];
} else {
    calendarsArray = [NSMutableArray arrayWithArray:[self.eventsStore calendarsForEntityType:EKEntityTypeEvent]];
}

I do receive 0 objects into calendarsArray. I've also tried to get it by "running through" all EKSources that are of type Local or CalDAV ([source calendarsForEntityType:] - got the same empty (0 object containing) set).

By the way - access to calendars IS granted.

Any suggestions?

Upvotes: 0

Views: 652

Answers (1)

Robert
Robert

Reputation: 11

After a brief investigation I have found out, that the problem was not in the code. It appears that the problem is in iOS 7.0.3 itself.

After deleting all the sync'ed calendars from the iDevice and adding it back all of the calendars were displayed both within the native Calendar application, and the one I made. After taking this action my code was able to retrieve the calendars from EventStore not depending on the method I would access calendars (via EKSources or EKEventStore itself).

Upvotes: 1

Related Questions