In this tutorial I teach you how to add Twitter integration into your iOS 5 apps.
Main Code:
-(IBAction)sendTweet
{
TWTweetComposeViewController *twitter = [[TWTweetComposeViewController alloc] init];
[twitter setInitialText:@"Hi Guys, This is a tweet from the iOS 5 Twitter integration tutorial. Coming Soon!"];
[twitter addURL:[NSURL URLWithString:[NSString stringWithFormat:@" / milmersxcode "]]];
if([TWTweetComposeViewController canSendTweet])
[self presentViewController:twitter animated:YES completion:nil];
else {
UIAlertView* alertView = [[UIAlertView alloc] initWithTitle:@"Unable to tweet"
message:@"This only works with iOS 5 and a good connection. Please try again later"
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:@"You successfully tweeted"
delegate:self cancelButtonTitle:@"OK"
otherButtonTitles:nil];
[alertView show];
[alertView release];
} else if (res == TWTweetComposeViewControllerResultCancelled) {
UIAlertView* alertView = [[UIAlertView alloc] initWithTitle:@"Oh Dear"
message:@"Tweet Failed to send, try again later"
delegate:self
cancelButtonTitle:@"OK"
otherButtonTitles:nil];
[alertView show];
[alertView release];
}
[self dismissModalViewControllerAnimated:YES];
[twitter release];
};
}
Don't forget to import Twitter.h!
Twitter: / failcakeapps
Apple Developer Center: http://developer.apple.com/devcenter/...
Website: http://failcake.webs.com/
Channel: / milmersxcode