2011-11-19

iOS5に組み込まれたTwitter機能をアプリで使う

iOS5には、Twitterとの連携機能が含まれている。これを使えば、ユーザはアプリごとにログインを行わなくて済むようになる。 Twitterとの連携機能を、アプリに組み込むのは簡単だ。Twitter.frameworkへのリンクを追加した後で、おおよそ次のようなコードを書けばよい。
#import <Twitter/TWTweetComposeViewController.h>

- (void)sendTweet
{
    TWTweetComposeViewController *tweetViewCtrl = [[[TWTweetComposeViewController alloc] init] autorelease];
    [tweetViewCtrl setInitialText:@"デフォルトのテキスト"];
    [self presentModalViewController:tweetViewCtrl 
                            animated:YES];
}