0

我最近发现,我没有从 iOS7 中的 EKEventStore 收到任何 EKCalendar 对象。在 iOS 6.xx 中,相同的代码片段没有问题。当我尝试访问 defaultCalendarForNewEvents - 我确实收到了一个 EKCalendar 对象(如预期的那样)。

我确实请求访问实体类型 EKEntityTypeEvent。

片段:

__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]];
}

我确实收到了 0 个对象到 calendarsArray。我还尝试通过“运行”所有类型为 Local 或 CalDAV 的 EKSource 来获得它([source calendarsForEntityType:] - 得到相同的空(包含 0 个对象)集)。

顺便说一句 - 授予访问日历的权限。

有什么建议么?

4

1 回答 1

1

经过简短的调查,我发现问题不在代码中。看来问题出在 iOS 7.0.3 本身。

从 iDevice 中删除所有同步的日历并将其重新添加后,所有日历都显示在本机日历应用程序和我制作的应用程序中。采取此操作后,我的代码能够从 EventStore 中检索日历,而不取决于我将访问日历的方法(通过 EKSources 或 EKEventStore 本身)。

于 2013-11-26T10:03:09.240 回答