【问题标题】:Eventkit Cannot Access CalendarEventkit 无法访问日历
【发布时间】:2012-10-29 05:06:57
【问题描述】:

我无法使用 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):“此应用没有访问权限到你的日历”

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

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

【问题讨论】:

    标签: objective-c ios permissions calendar eventkit


    【解决方案1】:

    您可以申请访问权限

    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) 添加一个键,该键将在请求所述访问时显示一个字符串。

    【讨论】:

    • 我看到这个回调在主线程之外被调用,在我发现之前给我带来了问题。
    猜你喜欢
    • 2013-06-16
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多