iOS - твиттер из двух частей - PullRequest
0 голосов
/ 27 декабря 2011

У меня есть приложение, заполняющее лист твита для пользователя, и иногда оно может содержать более 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];

        }

    }

}

любая помощь приветствуется.

1 Ответ

0 голосов
/ 02 января 2012

Вы должны использовать сокращатели URL для уменьшения размера URL, чтобы публиковать их в твиттере Facebook ... Для этого вы можете обратиться к этой ссылке. Это простая кодировка для сокращения любого типа URL, который у вас есть.можно сократить 2 части поста в один .. Надеюсь, это поможет вам ....

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

Всего наилучшего ....

Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...