Created
January 9, 2012 22:30
-
-
Save bkenny/1585343 to your computer and use it in GitHub Desktop.
Twitter iOS Native
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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