У меня есть приложение, заполняющее лист твита для пользователя, и иногда оно может содержать более 140 символов, включая URL.Я пытаюсь разработать метод, который может разделить твит на две части и сначала опубликовать часть 2, а затем часть 1, чтобы он выглядел следующим образом:
(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];
}
}
}
любая помощь приветствуется.