2013/07/15

[Twitter][iOS][Objective-C]Twitterの認証を行う

iOS5からtwitterの認証がデフォルトで装備されましたが、一体どうやって使うの?

色々調べた結果、めちゃくちゃ簡単に使えることが判明。

#import <Accounts/Accounts.h>
ACAccountStore *aCAccountStore = [[ACAccountStore alloc] init];
ACAccountType *aCAccountType = [aCAccountStore accountTypeWithAccountTypeIdentifier:ACAccountTypeIdentifierTwitter];
[aCAccountStore requestAccessToAccountsWithType:aCAccountType withCompletionHandler:^(BOOL granted, NSError *error) {
    if (granted) {
        NSLog(@"grandted");        
    }else{
        NSLog(@"not grandted");
    }
}];
AccountsFrameworkをインポートして上のようにコードすればおk

gratedがYESの場合、twitterの情報を取得することができるようになります。
 photo twitter_login_zps83a4a823.jpg
上のようなアラートがでて、「OK」を押せば取得することができるようになります。

むちゃくちゃ便利。

0 コメント:

コメントを投稿