2011-12-27 36 views
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]; 

     } 

    } 

} 

任何幫助表示讚賞。

回答

0

你必須使用網址縮短爲減少URL大小的Facebook的嘰嘰喳喳張貼......對於您可以參考這個link..This是一個簡單的編碼,以縮短任何類型的URL的U have..So u能減少後期到single..I希望這會幫助你的第2部分....

http://www.icodeblog.com/2010/02/04/iphone-coding-recipe-shortening-urls/

所有最優秀的....

+1

據我所知,Twitter的自動縮短任何URL到19個字符。我最終創建了一種遞歸方法,在必要時使用推文表將推文分成多個部分。 – bdaniels 2012-01-09 06:47:35