iOS返回说手机上没有推特账号,尽管有账号

我检查是否有使用此代码的Twitter帐户:

ACAccountStore *accountStore = [[ACAccountStore alloc] init]; ACAccountType *accountType = [accountStore accountTypeWithAccountTypeIdentifier:ACAccountTypeIdentifierTwitter]; NSArray *arrayOfAccounts = [accountStore accountsWithAccountType:accountType]; 

如果我在带有twitter帐户的iOS 6模拟器上运行它,则arrayOfAccounts.count为1,但在iPhone 4 iOS6上, arrayOfAccounts.count为0。

我究竟做错了什么?

我也有同样的问题。 使用此代码。

原因是它没有获得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; } } }