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