我使用Twitter框架发送tweet。我想将一些数据从应用程序传递给tweeter但是它不能。
我的代码。 `
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];
`
我的数据在共享字符串中。但它没有设置为初始文本。
怎么解决?
答案 0 :(得分: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];
};
}