How to post Tweets with iOS5


  1. Add Twitter framework to your project
  2. #import "Twitter/TWTweetComposeViewController.h"
  3. Add this code:
TWTweetComposeViewController *twitter = [[TWTweetComposeViewController alloc] init];
    
    [twitter setInitialText:@"It's really that simple!"];
    [twitter addImage:[UIImage imageNamed:@"twitter.png"]];

    [self presentViewController:twitter animated:YES completion:nil];
       
    twitter.completionHandler = ^(TWTweetComposeViewControllerResult res) {
        
        if(res == TWTweetComposeViewControllerResultDone)
        {
            
            UIAlertView* alertView = [[UIAlertView alloc] initWithTitle:@"Succes!" message:@"Your Tweet was posted succesfully" delegate:self cancelButtonTitle:@"OK" otherButtonTitles:nil];
            
            [alertView show];
            
            
        }else if(res == TWTweetComposeViewControllerResultCancelled)
        {
            
            UIAlertView* alertView = [[UIAlertView alloc] initWithTitle:@"Error" message:@"Your Tweet was not posted" delegate:self cancelButtonTitle:@"OK" otherButtonTitles:nil];
            
            [alertView show];
            
        }
        
        [self dismissModalViewControllerAnimated:YES];
        
    };