Search code examples
iostwitterios6sharing

Post in Twitter from iOS 6


I want to configure send data to facebook and twitter. I have a big article. In facebook goes fine, but Twitter is empty. I understand that because of the amount of data greater than 140 characters.

How do I check to see if the data to send to facebook send all article. And if the data is sent to Twitter sent only 140 characters.

Thank you very much

    NSArray *activityItems;
    NSString *myText = [self.webview stringByEvaluatingJavaScriptFromString:@"document.documentElement.innerText"];
    NSLog(@"my text -> %@",myText);
    NSString *path = ([self.data isKindOfClass:[NSArray class]]?[NSString stringWithFormat:@"%@-%d",self.key,selectedCategory]:self.key);
    NSString *string = [NSString stringWithFormat:@"%@.jpg", path];
    UIImage *image = [UIImage imageNamed:string];
        activityItems = @[myText, image];
   UIActivityViewController* activityViewController =
    [[UIActivityViewController alloc] initWithActivityItems:activityItems
                                      applicationActivities:nil];
    [self presentViewController:activityViewController animated:YES completion:^{}];

Solution

  • A very simple / quick and dirty check would be to just count the number of characters in your string, like this:

    if ([string length] <= 140) {
       // Good for Twitter
    } else {
       // Too long
    }
    

    Twitter does shorten URLs, which means that sometimes you may be allowed longer tweets than 140 characters. If you were presenting the social sheet directly you could use the setInitialText method to check whether it was an acceptable length, but you're using the activity view controller instead.