I’m using the following code to get access to a user’s twitter account:
ACAccountStore *store = [[ACAccountStore alloc] init];
ACAccountType *twitterAccountType =
[store accountTypeWithAccountTypeIdentifier:ACAccountTypeIdentifierTwitter];
// Request access from the user for access to his Twitter accounts
[store requestAccessToAccountsWithType:twitterAccountType
withCompletionHandler:^(BOOL granted, NSError *error) {
if (!granted) {
NSLog(@"User rejected access to his account.");
}
else {
NSArray *arrayOfAccounts = [store accountsWithAccountType:twitterAccountType];
if ([arrayOfAccounts count] > 0) {
ACAccount *acct = [arrayOfAccounts objectAtIndex:0];
}
}];
My question is, how do I save the user’s account in between app sessions? For the current session I can store it in an instance variable, but if the user exits the app and comes back, how do I get that account? Do I have call [store requestAccessToAccountsWithType:twitterAccountType...]? every time?
You can save the
TWAccount.identifier, and then use[ACAccountStore accountWithIdentifier]to retrieve that same account later.