Advertisement
Guest User

iOS 6 Twitter Type diasappearing

a guest
Dec 7th, 2012
58
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. - (IBAction)TwitterButtonClicked: (UIButton *)sender {
  2.     // Is Twitter accessible and is there at least one account
  3.     // setup on the device
  4.     if ([SLComposeViewController isAvailableForServiceType:SLServiceTypeTwitter]) {
  5.        
  6.         //create store and try to get access
  7.         ACAccountStore *account = [[ACAccountStore alloc] init];
  8.         ACAccountType *accountType = [account accountTypeWithAccountTypeIdentifier:
  9.                                       ACAccountTypeIdentifierTwitter];
  10.        
  11.         [account requestAccessToAccountsWithType:accountType options:nil
  12.                                       completion:^(BOOL granted, NSError *error)
  13.          {
  14.                      
  15.              //If user grants the app access
  16.              if (granted == YES)
  17.              {
  18.                  
  19.                  //Multiple Twitter accounts present?
  20.                  NSArray *arrayOfAccounts = [account
  21.                                              accountsWithAccountType:accountType];
  22.                  
  23.                  for (ACAccount *acc in arrayOfAccounts) {
  24.                      [acc accountType].identifier;
  25.                      //Otherwise the identifier get lost - god knows why -__-
  26.                  }
  27.                  
  28.                  
  29.                  
  30.                  dispatch_async(dispatch_get_main_queue(), ^{
  31.                      if ([arrayOfAccounts count] > 1)
  32.                      {
  33.                          self.alertDelegate = [AccountHandler
  34.                                                initWithAccounts: arrayOfAccounts];
  35.                          UIAlertView *message =
  36.                          [[UIAlertView alloc] initWithTitle:@"Multiple Accounts Detected!"
  37.                                                     message:@"Please pick the account you used \
  38.                          to sign up for ComicBin."
  39.                                                    delegate:[self alertDelegate]
  40.                                           cancelButtonTitle:@"Cancel"
  41.                                           otherButtonTitles:nil];
  42.                          
  43.                          for (ACAccount *acc in arrayOfAccounts) {
  44.                              [message addButtonWithTitle: [acc accountDescription]];
  45.                          }
  46.                          
  47.                          [message show];
  48.                          
  49.                      } else {
  50.                          ACAccount *acc = [arrayOfAccounts lastObject];
  51.                          //Just one account
  52.                          [AccountHandler checkAccountOf:acc];
  53.                      }
  54.                  });
  55.                  
  56.                  
  57.                  
  58.              } else {
  59.                  //Access denied
  60.                  UIAlertView *message = [[UIAlertView alloc] initWithTitle:@"Access denied"
  61.                                                                    message:@"Could not obtain right to use linked \
  62.                                         Twitter account. Please allow this app access to your Twitter account(s)"
  63.                                                                   delegate:nil
  64.                                                          cancelButtonTitle:@"OK"
  65.                                                          otherButtonTitles:nil];
  66.                  [message show];
  67.              }
  68.  
  69.          }];
  70.     } else {
  71.         UIAlertView *message = [[UIAlertView alloc] initWithTitle:@"No linked Twitter accounts"
  72.                                                           message:@"It looks like you have not linked \
  73.                                                    any Twitter accounts to your iPhone"
  74.                                                          delegate:nil
  75.                                                 cancelButtonTitle:@"OK"
  76.                                                 otherButtonTitles:nil];
  77.         [message show];
  78.        
  79.     }
  80.    
  81. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement