Strange behaviour when trying to use Twitter ACAccount Strange behaviour when trying to use Twitter ACAccount ios ios

Strange behaviour when trying to use Twitter ACAccount


I was also getting "Invalid account type for this request" when using SLRequest on accounts retrieved via both of the following

ACAccountStore *account_store = [[ACAccountStore alloc] init];ACAccountType *account_type_twitter = [account_store accountTypeWithAccountTypeIdentifier:ACAccountTypeIdentifierTwitter];// A.NSArray *accounts = [account_store accountsWithAccountType:account_type_twitter]; // B.NSString *account_id = @"id from doing account.identifier on one of the above";ACAccount *account = [account_store accountWithIdentifier:account_id];

NSLog on the account had everything populated as expected but the type was set as null. Guessing this is a bug with Apple's SDK. Doing the following fixed the accounts for me so I could use them with SLRequest:

ACAccountType *account_type_twitter = [account_store accountTypeWithAccountTypeIdentifier:ACAccountTypeIdentifierTwitter];account.accountType = account_type_twitter;


You have to retain ACAccountStore:

@property (nonatomic, strong) ACAccountStore *accountStore;

The ACAccount documentation never states specifically that you must retain ACAccountStore, but it does state that

"To create and retrieve accounts from the Accounts database, you must create an ACAccountStore object. Each ACAccount object belongs to a single ACAccountStore object."

When you call:

NSArray *accounts = [accountStore accountsWithAccountType:accountType]

Those accountStore objects in the array don't necessarily have all of their properties fetched from the database. Some properties (like accountType) are only retrieved from the Accounts database if needed. This caused the strange behavior that you saw when you logged the account and everything magically worked. When you logged the account, the ACAccountStore object was still in memory and the logging caused the retrieval of the AccountType property. At that point, the AccountType was retained with the ACAccount and everything was able to work later even after ACAccountStore was released.


Are you retaining the ACAccountStore you used to fetch the arraryOfAccounts?