我无法使用Eventkit访问设备的日历。我正在使用EKEventEditViewController呈现用于添加日历项的视图。

EKEventStore *eventStore = [[EKEventStore alloc] init];
EKEventEditViewController *eventController = [[EKEventEditViewController alloc]init];
eventController.eventStore = eventStore;
eventController.editViewDelegate = self;

...

[self presentViewController:eventController animated:YES completion:nil];

在模拟器上可以正常运行,但是在手机(iOS6)上运行该模拟器时,我收到以下错误消息:“此应用无权访问您的日历”

按照建议检查隐私设置根本不会显示我的应用程序的任何条目。

如何解决此问题并授予访问权限?

最佳答案

您可以请求访问

EKEventStore *store = [[EKEventStore alloc] init];
if([store respondsToSelector:@selector(requestAccessToEntityType:completion:)]) {
    [store requestAccessToEntityType:EKEntityTypeEvent completion:^(BOOL granted, NSError *error) {
        /* This code will run when uses has made his/her choice */
    }];
}

您也可以将一个密钥添加到plist(NSCalendarsUsageDescription)中,该密钥将在请求所述访问时显示字符串。

关于objective-c - Eventkit无法访问日历,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/13298590/

10-14 20:17
查看更多