UIAlertView does not work in completion handler block

I am writing code to access my Twitter user account, but I am having problems handling the case when there are no accounts on the device. What I would like to do is to show a warning informing the user that for authentication via Twitter they will first need to create an account in their settings.

Here is my code:

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 settings menu to add your Twitter account." delegate:nil cancelButtonTitle:@"OK" otherButtonTitles:nil, nil];
                [alert show]; //triggers an error
                break;

        }
    } 
}];

I'm not an expert in the Xcode debugger, but apparently an error occurs in the ACAccountStoreReply thread, about 25 calls in depth after calling [alert show] in a process called ucol_getVersion. The debugger state is EXC_BAD_ACCESS (code = 2, address = 0xcc).

Qaru UIAlertViews, , ( ), AccessToAccountsWithType.

, - Objective-C, 4- .

.

+5
1

, . UIAlertView dispatch_async:

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

nil .

+21

All Articles