尝试运行此代码时出现 EXEC_BAD_ACCESS 错误,并且用户不允许访问日历。requestAccessToEntityType 是否在单独的线程上运行,如果是这种情况,我如何访问主线程以显示 UIAlertView?
EKEventStore *store = [[EKEventStore alloc] init];
if ([store respondsToSelector:@selector(requestAccessToEntityType:completion:)])
{
[store requestAccessToEntityType:EKEntityTypeEvent completion:^(BOOL granted, NSError *error)
{
if ( granted )
{
[self readEvents];
}
else
{
UIAlertView *alert = [[UIAlertView alloc]
initWithTitle:@"Denied Access To Calendar"
message:@"Access was denied to the calendar, please go into settings and allow this app access to the calendar!"
delegate:nil
cancelButtonTitle:@"Ok"
otherButtonTitles:nil,
nil];
[alert show];
}
}];
}