Pregunta

I'm trying to integrate Ios 6 and twitter to send a tweet using slcomposeviewcontroller, but I cannot figure out how to get user info from twitter account.

Can anybody help me?

¿Fue útil?

Solución

You were on the right track, but you were using the wrong framework. The SLComposeViewController class in the social framework is only meant for sharing. If you want to get information about the currently signed in account, then you have to use the Accounts Framework.

#import <Accounts/Accounts.h>


- (void)getTwitterAccountInformation
{
    ACAccountStore *accountStore = [[ACAccountStore alloc] init];
    ACAccountType *accountType = [accountStore accountTypeWithAccountTypeIdentifier:ACAccountTypeIdentifierTwitter];

    [accountStore requestAccessToAccountsWithType:accountType options:nil completion:^(BOOL granted, NSError *error) {
        if(granted) {
            NSArray *accountsArray = [accountStore accountsWithAccountType:accountType];

            if ([accountsArray count] > 0) {
                ACAccount *twitterAccount = [accountsArray objectAtIndex:0];
                NSLog(@"%@",twitterAccount.username);
                NSLog(@"%@",twitterAccount.accountType);
            }
        }
    }];
}
Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top