(iOS7,xCode 5.1)我有一个应用程序可以出于各种目的访问日历,并且我正在尝试将所有错误消息都放在适当的位置。
我有 2 UIAlertviews
。两者都UIAlertviews
在我需要时显示,但我只接到didDismissWIthButtonIndex
其中一个的电话。调用的警报视图_iCloudAlert
是有效的。
如果我显示_iCloudAlert
,我会didDismissWIthButtonIndex
在单击按钮时接到电话,但是当我显示时,_deniedAccessAlert
我根本没有接到电话。我什至看不到最外面NSLog
的/s。
我<UIAlertviewDelegate>
的.h
档案里有。
显示警报的代码,具体取决于日历访问:
// Check the authorization status of our application for Calendar
-(void)checkEventStoreAccessForCalendar
{
NSLog(@"Check Status");
EKAuthorizationStatus status = [EKEventStore authorizationStatusForEntityType:EKEntityTypeEvent];
switch (status)
{
// Update our UI if the user has granted access to their Calendar
case EKAuthorizationStatusAuthorized: [self accessGrantedForCalendar];
NSLog(@"Already granted");
break;
// Prompt the user for access to Calendar if there is no definitive answer
case EKAuthorizationStatusNotDetermined: [self requestCalendarAccess];
break;
// Display a message if the user has denied or restricted access to Calendar
case EKAuthorizationStatusDenied:
case EKAuthorizationStatusRestricted:
{
NSLog(@"already denied");
[self performSelectorOnMainThread:@selector(showDeniedAccessAlert) withObject:nil waitUntilDone:NO];
}
break;
default:
break;
}
}
两种警报视图方法:
- (void)informUserAboutCloud {
_iCloudAlert = [[UIAlertView alloc]
initWithTitle: @"Important!"
message: @"If you have an iCloud account.....blah, blah, blah..."
delegate:self
cancelButtonTitle:@"OK"
otherButtonTitles:nil];
[_iCloudAlert show];
}
- (void)showDeniedAccessAlert {
NSLog(@"Show Denied Access Alert");
_deniedAccessAlert = [[UIAlertView alloc]
initWithTitle: @"Attention!"
message: @"It looks like you've blocked access to Calendar data... Blah, Blah, Blah..."
delegate: nil
cancelButtonTitle:@"OK"
otherButtonTitles:nil];
[_deniedAccessAlert show];
}
这是用于对按钮单击采取操作的代码:
- (void)alertView:(UIAlertView *)alert didDismissWithButtonIndex:(NSInteger)buttonIndex {
NSLog(@"button index: %i", buttonIndex); //only logs when _iCloudAlert is shown
NSLog(@"alertview: %@", alert); //only logs when _iCloudAlert is shown
if (_iCloudAlert) {
[self checkEventStoreAccessForCalendar];
NSLog(@"check for calendar access from dismissed icloud alert...");
}
if (_deniedAccessAlert) {
NSLog(@"dismissed denied access..."); //never logged
}
}