0

这是我用来访问存储在设备上的 twitter 帐户的代码;在我的设备上加载往往需要大约 30 秒(在模拟器上要快得多)

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];
     }
 }];
4

0 回答 0