我也遇到了同样的问题。使用此代码。
原因是它没有从 Twitter 帐户访问设置中获得权限,所以我们需要先检查一下。
if ([TWRequest class])
{
ACAccountStore *account = [[ACAccountStore alloc] init];
ACAccountType *accountType = [account accountTypeWithAccountTypeIdentifier:
ACAccountTypeIdentifierTwitter];
[account requestAccessToAccountsWithType:accountType options:nil
completion:^(BOOL granted, NSError *error)
{
if (granted == YES)
{
// Get account and communicate with Twitter API
NSArray *arrayOfAccounts = [account
accountsWithAccountType:accountType];
if ([arrayOfAccounts count] > 0)
{
ACAccount *twitterAccount = [arrayOfAccounts lastObject];
}
}
else
{
NSLog(@"No Twitter Access Error");
return;
}
}];
}
if ([TWRequest class])
{
ACAccountStore *as = [[ACAccountStore alloc] init];
ACAccountType *accountType = [as accountTypeWithAccountTypeIdentifier:ACAccountTypeIdentifierTwitter];
NSArray *twitterAccounts = [as accountsWithAccountType:accountType];
if (!twitterAccounts.count)
{
NSLog(@"No Twitter Account configured");
return;
}
}
}