LoginSignup
17
19

More than 5 years have passed since last update.

iOSと連携しているSNSのアカウント情報取得方法

Posted at

今はTwitterだけだけど、iOS6でFacebookとか増えるので。
詳しくは
https://developer.apple.com/library/ios/#documentation/Accounts/Reference/ACAccountStoreClassRef/Reference/Reference.html
https://developer.apple.com/library/ios/#documentation/Accounts/Reference/ACAccountClassRef/Reference/Reference.html

ACSample

@implementation ACSample

- (void)sample {
    ACAccountStore *accountStore = [[ACAccountStore alloc] init];
    // 今回はTwitterのアカウント取得するよ
    ACAccountType *accountType = [accountStore accountTypeWithAccountTypeIdentifier:ACAccountTypeIdentifierTwitter];

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

            if ([accountsArray count] > 0) {
                // 複数連携されてる場合もあるよ
                ACAccount *twitterAccount = [accountsArray objectAtIndex:0];
            }
        } else {
            // ユーザーにアカウントへのアクセス拒否されたりするとこっちに来るよ
        }
    }];
}

@end

17
19
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
17
19