Radislav
Radislav

Reputation: 2983

How to send a tweet from selected twitter account

In my application I want to show all list of twitter accounts and allow user to select one of them to send tweets. How to send tweet from selected account? Is it possible? Here is my code. I send data but it always uses first account...

ACAccountStore *accountStore = [[ACAccountStore alloc] init];
ACAccountType *accountType = [accountStore accountTypeWithAccountTypeIdentifier:ACAccountTypeIdentifierTwitter];
ACAccount *twitterAccount = [[accountStore accountsWithAccountType:accountType] objectAtIndex:0];
NSString *userName = [twitterAccount username];
NSLog(@"%@", userName);
TWTweetComposeViewController *twitter =
[[TWTweetComposeViewController alloc] init];
[twitter setInitialText:@"Hello"];
[twitter addURL:[NSURL URLWithString:_baseUrl]];
[tableViewController presentViewController:twitter animated:YES completion:nil];

Upvotes: 3

Views: 1049

Answers (1)

WrightsCS
WrightsCS

Reputation: 50717

The reason you are always choosing the first account if because you have this:

ACAccount *twitterAccount = [[accountStore accountsWithAccountType:accountType] objectAtIndex:0];

Why are you choosing the account for the user anyway? You should let the user decide which account they want to send the tweet from.

Also, the Tweet Composer should have an option to select which Twitter account to use if there are multiple account anyway.

Upvotes: 2

Related Questions