SLComposecontroller does not disable post button for long messages

67 views Asked by At

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?

1

There are 1 answers

1
Alex Cio On

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
    }
}