1

I used SLComposerController, but it is not disabling the post button when the character count exceeds 140 character . I want to post an URL ,image and initial text on Twitter via my iOS application. How to do this?

Alex Cio
  • 6,014
  • 5
  • 44
  • 74
shweta
  • 11
  • 4
  • 3
    Can you please provide some code? – Alex Cio Jun 19 '15 at 11:19
  • You can shorten URL and then allow it use with your Twit text. – Hemang Jun 19 '15 at 11:56
  • here is my code [tweetSheet setInitialText: [NSString stringWithFormat:@"Hey friends! You gotta download this app %@ ",sharingURL]]; if (!SYSTEM_VERSION_GREATER_THAN_OR_EQUAL_TO(@"8.0")) { [tweetSheet addURL:[NSURL URLWithString:@"add.it"]]; } [tweetSheet addImage:[UIImage imageNamed:@"twitter_ad.png"]]; [self presentViewController:tweetSheet animated:NO completion:^{ }]; If i enter the character after url then that post button is not going to disable – shweta Jun 19 '15 at 12:06

1 Answers1

0

It is up to the user to set the correct length to send, but I think it won't send if it is too long, or give you a callback if it didn't work.

Here is what I did:

-(void) postOnTwitterInsideView:(UIViewController *)viewController 
                        message:(NSString *)postMessage{

    if( [SLComposeViewController isAvailableForServiceType:SLServiceTypeTwitter] ){
        SLComposeViewController *twitterPost = [SLComposeViewController
                                                composeViewControllerForServiceType:SLServiceTypeTwitter];

        [twitterPost setCompletionHandler:^(SLComposeViewControllerResult result){
            switch (result) {
                case SLComposeViewControllerResultDone:
                    // tell user message was sent
                    break;

                case SLComposeViewControllerResultCancelled:
                    // tell user message was not sent
                    break;
                default:
                    break;
            }
        }];

        [twitterPost addImage:self.imagePost];
        [twitterPost setInitialText:postMessage];
        [viewController presentViewController:twitterPost 
                                     animated:YES 
                                   completion:nil];
    } else {
        // tell user he has to activate this service in his settings of iOS
    }
}
Alex Cio
  • 6,014
  • 5
  • 44
  • 74
  • but still user is putting extra character then that post button should get disable and am not able to do this in my application.i have done same coding – shweta Jun 19 '15 at 11:50