iOS5中Twitter上的照片发布

时间:2012-08-08 07:49:41

标签: ios5 twitter

我是iOS5中twitter集成的新手。

我需要在Twitter上发布来自服务的照片。

我搜索了很多,并且还练习了这方面的示例教程。 我只获得照片网址。我需要张贴照片。

任何人都可以帮我这个吗? 提前谢谢。

1 个答案:

答案 0 :(得分:0)

首先,您需要保存图像,然后您可以将保存的图像发布到Twitter

 self.shareImg.image = [UIImage imageNamed:@"Your Saved image"];

 if ([[[UIDevice currentDevice] systemVersion] floatValue] > 5.0) {
        // Create the view controller
        TWTweetComposeViewController *twitter = [[TWTweetComposeViewController alloc] init];

        NSString *str = [NSString stringWithFormat:@"I created this photo http://%@", iTune];

        // Optional: set an image, url and initial text
        [twitter addImage:self.shareImg.image];

        [twitter setInitialText:[NSString stringWithFormat:@"I created this photo using USC Project Trojan App:http://uslofphoto.com. Download http://%@", iTune]];

        // Show the controller
        [self presentModalViewController:twitter animated:YES];

        // Called when the tweet dialog has been closed
        twitter.completionHandler = ^(TWTweetComposeViewControllerResult result) 
        {
            NSString *title = @"Tweet Status";
            NSString *msg; 

            if (result == TWTweetComposeViewControllerResultCancelled)
                msg = @"Tweet compostion was canceled.";
            else if (result == TWTweetComposeViewControllerResultDone)
                msg = @"Tweet composition completed.";

            // Show alert to see how things went...
            UIAlertView* alertView = [[UIAlertView alloc] initWithTitle:title message:msg delegate:self cancelButtonTitle:@"Okay" otherButtonTitles:nil];
            [alertView show];

            // Dismiss the controller
            [self dismissModalViewControllerAnimated:YES];
        };
    }