Ios UIAlertView没有';在完成处理程序块中不工作

Ios UIAlertView没有';在完成处理程序块中不工作,ios,objective-c,Ios,Objective C,我正在编写代码以访问用户的Twitter帐户,但在处理设备上没有帐户的情况时遇到了问题。我想做的是显示一个警报,告诉用户,为了使用Twitter进行身份验证,他们首先需要在自己的设置中创建帐户 这是我的密码: self.accountStore = [[ACAccountStore alloc] init]; ACAccountType *accountTypeTwitter = [self.accountStore accountTypeWithAccountTypeIdentifier:AC

我正在编写代码以访问用户的Twitter帐户,但在处理设备上没有帐户的情况时遇到了问题。我想做的是显示一个警报,告诉用户,为了使用Twitter进行身份验证,他们首先需要在自己的设置中创建帐户

这是我的密码:

self.accountStore = [[ACAccountStore alloc] init];
ACAccountType *accountTypeTwitter = [self.accountStore accountTypeWithAccountTypeIdentifier:ACAccountTypeIdentifierTwitter];

[self.accountStore requestAccessToAccountsWithType:accountTypeTwitter options:nil completion:^(BOOL granted, NSError *error) {
    if(granted) {
        //Doesn't matter for the present case
    } else if (error){

        [SVProgressHUD dismiss]; //not directly relevant to the present question, but it also doesn't work within the block, so I'm leaving it as a clue

        switch ([error code]){
            case (6):

                UIAlertView *alert = [[UIAlertView alloc]initWithTitle:@"No Twitter Account Detected" message:@"Please go into your device's settings menu to add your Twitter account." delegate:nil cancelButtonTitle:@"OK" otherButtonTitles:nil, nil];
                [alert show]; //triggers an error
                break;

        }
    } 
}];
我不是Xcode调试器的专家,但显然错误发生在ACAccountStoreReply线程中,在调用[alert show]之后,在一个名为ucol_getVersion的进程中,大约25次调用都会发生。调试器状态为EXC\U BAD\U访问(代码=2,地址=0xcc)

我在Stack Overflow和internet上搜索了关于UIAlertViews不在块中工作的解决方案,还搜索了显示警报的一般问题(我为委托尝试了不同的值),以及调用requestAccessToAccountsWithType的一般问题

我还试图通过阅读各种在线资源,以及Objective-C编程的相关页面,第四次添加,来复习我对积木的理解


非常感谢您的帮助。

您应该始终确保在主线程上完成任何UI交互。将您的
UIAlertView
调用包装为
dispatch\u async

dispatch_async(dispatch_get_main_queue(), ^{
   UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"No Twitter Account Detected" message:@"Please go into your device's settings menu to add your Twitter account." delegate:nil cancelButtonTitle:@"OK" otherButtonTitles:nil];
   [alert show];
});

在调用结束时,您还有两个
nil
s。

但是如果我想调用此alertview的委托方法??