从Twitter的Twitter框架获取Twitter的处理

我知道,要使用iOS 5中的twitter框架访问已configuration的Twitter帐户,可以执行以下操作:

ACAccountStore *t_account = [[ACAccountStore alloc] init]; ACAccountType *accountType = [account accountTypeWithAccountTypeIdentifier:ACAccountTypeIdentifierTwitter]; [account requestAccessToAccountsWithType:accountType withCompletionHandler:^(BOOL granted, NSError *error) { if (granted == YES) { } } 

但问题是,我不需要一个完整的帐户,我只是想要叽叽喳喳的名字,如果他已经在Twitter帐户上configuration任何。 那么,有没有办法从框架(而不是完整的帐户) 得到任何用户权限 只是叽叽喳喳句柄

未经用户授予访问这些帐户的权限,您将无法访问任何帐户。 只需在新项目的应用程序代理中尝试以下操作,即可知道应用程序尚未获得访问Twitter帐户的权限。 当然,请确保您的设备或模拟器上至less有一个Twitter帐户,并在项目和应用程序委托中导入帐户框架。 你也假设用户只有一个Twitter帐户。 最好代码的情况下,用户可能有多个帐户。

  ACAccountStore *accountStore = [[ACAccountStore alloc] init]; // Create an account type that ensures Twitter accounts are retrieved. ACAccountType *accountType = [accountStore accountTypeWithAccountTypeIdentifier:ACAccountTypeIdentifierTwitter]; NSArray *accountsArray = [accountStore accountsWithAccountType:accountType]; for (ACAccount *account in accountsArray ) { NSLog(@"Account name: %@", account.username); } NSLog(@"Accounts array: %d", accountsArray.count); 

现在,更改代码以在用户授予权限时返回结果:

  ACAccountStore *accountStore = [[ACAccountStore alloc] init]; // Create an account type that ensures Twitter accounts are retrieved. ACAccountType *accountType = [accountStore accountTypeWithAccountTypeIdentifier:ACAccountTypeIdentifierTwitter]; [accountStore requestAccessToAccountsWithType:accountType withCompletionHandler:^(BOOL granted, NSError *error) { if(granted) { NSArray *accountsArray = [accountStore accountsWithAccountType:accountType]; for (ACAccount *account in accountsArray ) { NSLog(@"Account name: %@", account.username); } NSLog(@"Accounts array: %d", accountsArray.count); } }]; 

所以我想简单的回答是,苹果要求用户授予用户帐户权限是有原因的。 如果该访问权限未被授予,则不会获取任何数据。