requestAccessToAccountsWithType完成未被调用

时间:2013-11-08 22:10:36

标签: objective-c twitter accounts social-framework

当我运行[_accountStore requestAccessToAccountsWithType:...]时,我没有得到任何回复。我的完成处理程序没有被调用。但是我可以访问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");
            }
        }];
    }

为什么会这样?

1 个答案:

答案 0 :(得分:4)

make shure _accountStore已初始化,例如

_accountStore = [[ACAccountStore alloc] init];
相关问题