Why does it take so long to load Twitter account from ACAccounts?

321 Views Asked by At

Here is the code I am using to access the twitter account stored on the device; it tends to take around 30 seconds to load on my device (it is much faster on the simulator)

ACAccountStore *account = [[ACAccountStore alloc] init];
ACAccountType *accountType = [account
                              accountTypeWithAccountTypeIdentifier:ACAccountTypeIdentifierTwitter];

[account requestAccessToAccountsWithType:accountType
                                 options:nil completion:^(BOOL granted, NSError *error)
 {
     if (granted == YES)
     {
         NSArray *arrayOfAccounts = [account
                                     accountsWithAccountType:accountType];

         if ([arrayOfAccounts count] > 0)
         {
             self.twitterAccount =
             [arrayOfAccounts lastObject];

             UIAlertView* loggedInAlert = [[UIAlertView alloc] initWithTitle:@"Success!" message:@"Successfully logged in to Twitter" delegate:self cancelButtonTitle:@"OK" otherButtonTitles:nil, nil];
             [loggedInAlert show];
         }
         else {
             NSLog(@"There are not any accounts to post to");
             self.twitterAccount = NULL;
             UIAlertView* noAccountAlert = [[UIAlertView alloc] initWithTitle:@"No Twitter Account Found" message:@"Check the settings of your device and make sure you are logged in to Twitter" delegate:self cancelButtonTitle:@"OK" otherButtonTitles:nil, nil];
             [noAccountAlert show];
         }
     } else {
         UIAlertView* alert = [[UIAlertView alloc] initWithTitle:@"Authentication Failed" message:@"Failed to gain access to Twitter account" delegate:nil cancelButtonTitle:@"OK" otherButtonTitles:nil, nil];
         [alert show];
     }
 }];
0

There are 0 best solutions below