入门Twitter的Twitter的框架处理中的iOS

问题描述:

我知道使用Twitter框架在iOS 5访问配置的Twitter帐户,下面可以做:入门Twitter的Twitter的框架处理中的iOS

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

但问题是,我不我不需要一个完整的帐户,我只是想要Twitter的名字,如果他已经在Twitter帐户上配置任何。那么,有没有办法让只是Twitter的处理从框架(未充分考虑)没有询问任何用户权限

如果没有用户授予访问这些帐户的权限,您将无法访问任何帐户。只需在新项目的应用程序代理中尝试以下操作,以便知道该应用程序尚未获得访问Twitter帐户的权限。当然,请确保您的设备或模拟器上至少有一个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); 
    } 
}]; 

所以我想简单的答案是,有一个苹果的理由要求用户授予权限的用户账户。如果该访问权限未被授予,则不会获取任何数据。

+0

是啊!我知道这个。现在我不认为有什么方法可以通过“用户权限弹出”,即使我不想要完整帐户。我只想要用户的Twitter处理,如果任何配置在Twitter帐户。 – defactodeity

+0

这就是我试图用更多的代码示例来回答这是为什么。除非:[accountStore requestAccessToAccountsWithType:accountType withCompletionHandler:^(BOOL granted,NSError * error)返回true为理所当然 – Michael

+0

谢谢Michael,我已经尝试了所有这些..但是我希望苹果有两种独立的帐户访问模式: 1)只能阅读和了解Twitter用户名。 2)可以有完整的Twitter帐户,可以读取/写入/发布任何数据到帐户。 – defactodeity