应用程序日历功能不再适用于ios 6

JLo*_*ewy 17 icalendar objective-c ios eventkit

在我正在开发的应用程序中,用户和用户日历之间存在交互,就像在许多应用程序中发生的那样,非常标准的东西.它正常工作,直到我升级到ios 6.我现在面临"这个应用程序无法访问您的日历.当我尝试执行相同的日历功能但我的应用程序执行时,您可以在隐私设置中启用访问"对话框未出现在设备日历隐私设置中.是否需要使用一些新的api才能要求用户授予访问权限?

非常感谢帮助我解决这个问题谁能提供帮助.

www*_*.se 28

我相信我有完全相同的问题.我正在使用iOS 6将我正在使用的应用程序的正常开发人员构建部署到我的iPhone 4上.

编辑:我终于解决了这个问题,我没有在网上找到信息,而是在API中找到了它.

运行以下命令以请求权限.这显然是异步调用,并且在用户授权应用程序之前不会授予访问权限.

EKEventStore *es = [[EKEventStore alloc] init];
[es requestAccessToEntityType:EKEntityTypeEvent completion:^(BOOL granted, NSError *error) {
    /* This code will run when uses has made his/her choice */
}];
Run Code Online (Sandbox Code Playgroud)

此外,您可以指定应用程序尝试使用Info.plist中的信息执行的操作.有一个名为Privacy - Calendars Usage Description(NSCalendarsUsageDescription)的密钥,它可以包含将在提示中显示给用户的字符串描述.

以下是我遇到的问题的全部细节(由上面修复):

当我尝试将事件添加到日历时,我会看到以下屏幕: 添加事件错误消息

当我打开日历隐私设置的设置时,看不到任何应用: 设置,隐私,日历

这一切都让我觉得我必须在Info.plist中设置一些设置来启用日历访问并询问用户启动权限.我在网上搜索但没找到任何东西.

@jloewy,我想这是你遇到的同样的问题?


Mon*_*ngo 9

如果您计划在iOS 6之前支持设备,我会添加以下内容,否则您将收到错误消息.

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 */
    }];
}
Run Code Online (Sandbox Code Playgroud)


til*_*ilo 7

如果您想等待用户响应请求,可以在接受的答案中添加一些代码行:

__block BOOL accessGranted = NO;

if([store respondsToSelector:@selector(requestAccessToEntityType:completion:)]) {
    dispatch_semaphore_t sema = dispatch_semaphore_create(0);
    [store requestAccessToEntityType:EKEntityTypeEvent completion:^(BOOL granted, NSError *error) {
        accessGranted = granted;
        dispatch_semaphore_signal(sema);
    }];
    dispatch_semaphore_wait(sema, DISPATCH_TIME_FOREVER);
} else { // we're on iOS 5 or older
    accessGranted = YES;
}

if (accessGranted) {
    // go on
}
Run Code Online (Sandbox Code Playgroud)