我最近发现,我没有从 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 个对象)集)。
顺便说一句 - 授予访问日历的权限。
有什么建议么?