Skip to content

Instantly share code, notes, and snippets.

@bkenny
Created January 9, 2012 22:30
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save bkenny/1585343 to your computer and use it in GitHub Desktop.
Save bkenny/1585343 to your computer and use it in GitHub Desktop.
Twitter iOS Native
// Don't forget to include Twitter/Twitter.h into your implementation for this to work!
// Both amountSavedString and numDaysString are simple strings containing... well what they say.
NSString *tweet = [NSString stringWithFormat:@"I've saved %@ by not smoking for %@ with @getkickit", amountSavedString, numDaysString];
TWTweetComposeViewController *twitter = [[TWTweetComposeViewController alloc] init];
[twitter setInitialText:tweet];
if([TWTweetComposeViewController canSendTweet])
[self presentViewController:twitter animated:YES completion:nil];
else {
UIAlertView* alertView = [[UIAlertView alloc] initWithTitle:@"Unable to tweet" message:@"You must be running iOS5 to send a tweet." delegate:self cancelButtonTitle:@"Dismiss" otherButtonTitles:nil];
[alertView show];
[alertView release];
return;
}
twitter.completionHandler = ^(TWTweetComposeViewControllerResult res)
{
if (res == TWTweetComposeViewControllerResultDone)
{
UIAlertView* alertView = [[UIAlertView alloc] initWithTitle:@"Tweet Successful!" message:@"Your tweet has been posted successfully." delegate:self cancelButtonTitle:@"OK" otherButtonTitles:nil];
[alertView show];
[alertView release];
}
else if (res == TWTweetComposeViewControllerResultCancelled)
{
UIAlertView* alertView = [[UIAlertView alloc] initWithTitle:@"Oooops!" message:@"Tweet Failed to send, try again later" delegate:self cancelButtonTitle:@"OK" otherButtonTitles:nil];
[alertView show];
[alertView release];
}
[self dismissModalViewControllerAnimated:YES];
[twitter release];
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment