質問

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?

役に立ちましたか?

解決

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);
            }
        }
    }];
}
ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top