我的应用程序填写了用户的推文表,有时它可能超过140个字符,包括网址。我正在尝试开发一种方法,可以将推文分成两部分,先发布第2部分,然后发布第1部分,看起来像:
(1/2)blah blah blah(2/2)blah blah blah
这是我到目前为止的方法:
(void)sendTweet:(NSString *)msg setURL:(NSString*)url setImg:(UIImage*)img {
// Set up the built-in twitter composition view controller.
TWTweetComposeViewController *tweetViewController = [[TWTweetComposeViewController alloc] init];
// Set the initial tweet text. See the framework for additional properties that can be set.
if (![tweetViewController addURL:[NSURL URLWithString:url]])
NSLog(@"Unable to add the URL!");
if (![tweetViewController addImage:img])
NSLog(@"Unable to add the image!");
if (![tweetViewController setInitialText:msg])
NSLog(@"Unable to add the message!");
// Create the completion handler block.
[tweetViewController setCompletionHandler:^(TWTweetComposeViewControllerResult result) {
NSString *output;
switch (result) {
case TWTweetComposeViewControllerResultCancelled:
// The cancel button was tapped.
output = @"Tweet cancelled.";
break;
case TWTweetComposeViewControllerResultDone:
// The tweet was sent.
output = @"Tweet sent.";
break;
default:
break;
}
// Show alert to see how things went...
UIAlertView* alertView = [[UIAlertView alloc]
initWithTitle:@"The Predictor"
message:output
delegate:nil
cancelButtonTitle:@"OK"
otherButtonTitles:nil];
[alertView show];
[alertView release];
// Dismiss the tweet composition view controller.
[self dismissModalViewControllerAnimated:YES];
}];
// Present the tweet composition view controller modally.
[self presentModalViewController:tweetViewController animated:YES];
}
以下是我如何调用它,虽然这两部分内容不起作用......我希望这个功能内置于上述方法中。
if ([alertView tag] == 1) {
if (buttonIndex != [alertView cancelButtonIndex]) {
NSString *theURL = @"PredictorApps.com";
NSString *theTweet = [NSString stringWithFormat:@"%@ - %@\n%@", [[Singleton sharedSingleton].spreadDate substringToIndex:5], theTitle, theMessage];
if (([theURL length] + [theTweet length]) <= 120)
[self sendTweet:theTweet setURL:theURL setImg:nil];
else if (([theURL length] + [theTweet length]) > 120) {
NSString *partTwo = [theTweet substringFromIndex:(([theURL length] + [theTweet length]) / 2)];
NSLog(@"Part Two: %@", partTwo);
[self sendTweet:partTwo setURL:theURL setImg:nil];
NSString *partOne = [theTweet substringToIndex:(([theURL length] + [theTweet length]) / 2)];
NSLog(@"Part One: %@", partOne);
[self sendTweet:partOne setURL:theURL setImg:nil];
}
}
}
感谢任何帮助。
答案 0 :(得分:0)
你必须使用URL缩短器来减少URL大小才能在facebook的twitter中发布...为此你可以参考这个链接。这是一个简单的编码,可以缩短你拥有的任何类型的URL。所以你可以将2个帖子减少到单个..我希望这会对你有帮助....
http://www.icodeblog.com/2010/02/04/iphone-coding-recipe-shortening-urls/
一切顺利......