2

Twitter フレームワークを使用してツイートを送信しました。アプリケーションからツイーターにデータを渡したいのですが、できません。

私のコード。`

        if ([TWTweetComposeViewController canSendTweet]) {

        // Initialize Tweet Compose View Controller
        TWTweetComposeViewController *vc = [[TWTweetComposeViewController alloc] init];
        UITextField *txtFild1=[[UITextField alloc]init];
        txtFild1.text=shareString;
        // Settin The Initial Text
        [vc setInitialText:self.shareString];
        [txtFild1 release];
        // Adding an Image

        // Adding a URL

        // Setting a Completing Handler
        [vc setCompletionHandler:^(TWTweetComposeViewControllerResult result) {
            [self dismissModalViewControllerAnimated:YES];
        }];

        // Display Tweet Compose View Controller Modally
        [self presentViewController:vc animated:YES completion:nil];

`

私のデータは共有文字列にあります。ただし、初期テキストとして設定されません。

どのように解決できますか?

4

1 に答える 1

2

最初にこのファイルを追加Twitter.frameworkしてからBuild Phases => LinkBinary with Libraries、次のようにファイルにインポートします.m...

#import <Twitter/TWTweetComposeViewController.h>

そして、これを次のように使用します..これは単なる例です..

- (IBAction)CallTwitter
{   
    TWTweetComposeViewController *twitter = [[TWTweetComposeViewController alloc] init];

    [twitter setInitialText:@"Write Some Text Here"];


    [self presentViewController:twitter animated:YES completion:nil];

    twitter.completionHandler = ^(TWTweetComposeViewControllerResult res) {

        if(res == TWTweetComposeViewControllerResultDone)
        {

            UIAlertView* alertView = [[UIAlertView alloc] initWithTitle:@"Success!" message:@"Your Tweet was posted succesfully" delegate:self cancelButtonTitle:@"OK" otherButtonTitles:nil];

            [alertView show];
            [alertView release];



        }else if(res == TWTweetComposeViewControllerResultCancelled)
        {

            UIAlertView* alertView = [[UIAlertView alloc] initWithTitle:@"Canceled" message:@"Your Tweet was not posted" delegate:self cancelButtonTitle:@"OK" otherButtonTitles:nil];

            [alertView show];
            [alertView release];
        }
        [self dismissModalViewControllerAnimated:YES];
    };
}
于 2013-01-07T12:24:32.930 に答える