我正在做一个涉及 iOS EventKit 的项目。它需要与 ios 5 向后兼容。所以我尝试实现了一些在 SO 上找到的方法。发生的情况是,当我尝试显示 UIAlert 时它会崩溃。
-(void)addToCalender {
EKEventStore *eventStore = [[EKEventStore alloc] init];
if ([eventStore respondsToSelector:@selector(requestAccessToEntityType:completion:)])
{
__block typeof (self) weakSelf = self; // replace __block with __weak if you are using ARC
[eventStore requestAccessToEntityType:EKEntityTypeEvent completion:^(BOOL granted, NSError *error)
{
if (granted)
{
//[weakSelf performSelectorOnMainThread:@selector(addEventToCalendar) withObject:nil waitUntilDone:YES];
[weakSelf performSelectorOnMainThread: @selector(presentEventEditViewControllerWithEventStore:) withObject:eventStore waitUntilDone:YES];
}
else
{
NSLog(@"Not granted");
UIAlertView *alert = [[UIAlertView alloc]
initWithTitle: @"Announcement"
message: @"It turns out that you are playing Addicus!"
delegate: nil
cancelButtonTitle:@"OK"
otherButtonTitles:nil];
[alert show];
[alert release];
}
}];
}
else
{
[self performSelectorOnMainThread: @selector(presentEventEditViewControllerWithEventStore:) withObject:eventStore waitUntilDone:NO];
}
}
我的错误信息相当模糊,但我猜它是关于不能被解雇的主要威胁的东西?
我不确定。但是,我还想在未设置权限时获得“此应用程序需要您的权限”对话框,这可能吗?