2012-10-13 121 views
1

iOS6。我在设置应用中登录了Twitter。accountsWithAccountType返回空数组

我关闭了我的应用程序,然后“设置”应用程序重新运行。

ACAccountStore *store = [[ACAccountStore alloc] init]; 
ACAccountType *accountType = [store accountTypeWithAccountTypeIdentifier:ACAccountTypeIdentifierTwitter]; 
[self createAccountPickerForAccountType:accountType withStore:store]; 

...

- (void)createAccountPickerForAccountType:(ACAccountType *)accountType withStore: 
self.accounts = [store accountsWithAccountType:accountType]; 
[self displayAccountPicker]; 

数组返回是一个空数组。

回答

5

我在手机上也看到了这一点,但它可以在模拟器中使用。

我做:

ACAccountStore *store = [[ACAccountStore alloc] init]; 
ACAccountType *twitterAccountType = 
[store accountTypeWithAccountTypeIdentifier:ACAccountTypeIdentifierTwitter]; 

[store requestAccessToAccountsWithType:twitterAccountType options:nil^(BOOL granted, NSError *error) { 

    NSArray *twitterAccounts = [store accountsWithAccountType:twitterAccountType]; 
    int count = [twitterAccounts count]; 
}]; 

https://dev.twitter.com/docs/ios-frequently-asked-questions

“为什么我的应用程序归结为 “从iOS版”,而不是 “从” 在twitter.com上

如果您的应用程序?尚未在App Store中生效:

发出请求的应用程序必须在Apple的App Store中启动才能将其归属为d在twitter.com上播放。需要注意的是应用程序的iOS5的版本必须是活的,不只是以前的版本“

我不知道,如果它可以,因为我的应用程序是不是在App Store尚未

+7

更新:?想通了你!必须要求权限(并授予它们)才能使用计数。要请求权限,请使用[ACAccountStore requestAccessToAccountsWithType] –