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.frameworkfromBuild 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 回答