【问题标题】:Can't retrieve EKCalendars from EKEventStore in iOS7无法从 iOS7 中的 EKEventStore 检索 EKCalendars
【发布时间】:2013-10-31 11:11:35
【问题描述】:

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

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

sn-p:

__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 个对象)集)。

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

有什么建议吗?

【问题讨论】:

  • 这发生在 iPhone 4 和 iPhone 5(都运行 iOS 7.0.3)上。此外,在两台设备上,还通过 CalDAV 连接了两个日历。
  • 另外,运行其他测试(编写附加应用程序等)我注意到在本地存储中也无法创建日历。

标签: objective-c ios7 ekeventkit


【解决方案1】:

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

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

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2018-08-25
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-10-30
    • 2016-11-02
    • 2020-06-20
    相关资源
    最近更新 更多