3

When I run [_accountStore requestAccessToAccountsWithType: ...] I am getting no response. My completion handler isn't being called. However I do have access to twitter.

    //  Step 0: Check that the user has local Twitter accounts
    if ([SLComposeViewController
     isAvailableForServiceType:SLServiceTypeTwitter]) {
        NSLog(@"OH YES!!!");
        //  Step 1:  Obtain access to the user's Twitter accounts
        ACAccountType *twitterAccountType = [_accountStore accountTypeWithAccountTypeIdentifier: ACAccountTypeIdentifierTwitter];
        NSLog(@"OH YES!!!");

        [_accountStore requestAccessToAccountsWithType:twitterAccountType options:nil
                                       completion:^(BOOL granted, NSError *error)
        {
            NSLog(@"Im in!");
            if (granted == YES)
            {
                NSArray *arrayOfAccounts = [_accountStore
                                            accountsWithAccountType:twitterAccountType];

                if ([arrayOfAccounts count] > 0)
                {
                    ACAccount *twitterAccount = [arrayOfAccounts lastObject];

                    NSLog(@"%@", twitterAccount.userFullName);
                    NSLog(@"%@", twitterAccount.username);
                    NSLog(@"%@", twitterAccount.credential);
                    NSLog(@"%@", twitterAccount.identifier);

                }
            }else{
                NSLog(@"Failed muahahaha");
            }
        }];
    }

Why is this happening?

Jargen89
  • 480
  • 1
  • 6
  • 19

1 Answers1

4

Make shure _accountStore is initialized for example with

_accountStore = [[ACAccountStore alloc] init];
adrian
  • 66
  • 2
  • I had figured out my issue yesterday. I did have it initialized, but in viewDidLoad. I didn't think it was an issue until I moved it into my function. Out of curiosity, why didn't it work when I had _accountStore initialized in viewDidLoad? – Jargen89 Nov 12 '13 at 14:29
  • Also, I forgot to add, that I had apparently blocked my app from using twitter. Slip of the finger lol Once I reset the settings on my device and changed that line of code, everything was fine. – Jargen89 Nov 12 '13 at 14:44