0
我有我的應用程序填寫用戶的推文表,有時它可能會超過140個字符,包括網址。我試圖開發一種能夠鳴叫分成兩個部分和後部分2的第一方法,以及然後部分1,以便它看起來像:iOS - twitter兩部分後
(1/2)等等等等等等
(2/2)等等等等等等
這裏的方法我到目前爲止:
(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];
}
}
}
任何幫助表示讚賞。
據我所知,Twitter的自動縮短任何URL到19個字符。我最終創建了一種遞歸方法,在必要時使用推文表將推文分成多個部分。 – bdaniels 2012-01-09 06:47:35