Objective c Eventkit无法访问日历
我无法使用Eventkit访问设备的日历。我正在使用EKEventEditViewController显示用于添加日历项的视图Objective c Eventkit无法访问日历,objective-c,ios,permissions,calendar,eventkit,Objective C,Ios,Permissions,Calendar,Eventkit,我无法使用Eventkit访问设备的日历。我正在使用EKEventEditViewController显示用于添加日历项的视图 EKEventStore *eventStore = [[EKEventStore alloc] init]; EKEventEditViewController *eventController = [[EKEventEditViewController alloc]init]; eventController.eventStore = eventStore; ev
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)添加一个键,该键在请求所述访问时将显示一个字符串。您可以请求访问
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)添加一个键,该键在请求所述访问时将显示一个字符串。我看到此回调在主线程之外被调用,在我捕获之前给我造成了问题。我看到此回调在主线程之外被调用,在我捕获之前给我造成了问题。