このコードを実行しようとすると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];
}
}];
}