I have been following iOS development using Head First book. If you have completed the second chapter, than you would have surely landed up with the problem that sending tweet does not work.
The reason why sending tweet does not work is because book was written way back and Twitter moved to OAuth authentication afterwards.
The simplest way to enable tweeting is to use Twitter Library in built in iOS framework.
Add the twitter framework in project. Change the code of send button to look like this
NSString* theMessage = [NSString stringWithFormat:@”I’m %@ and feeling %@ about it.”, [activities objectAtIndex:[tweetPicker selectedRowInComponent: 0]], [feelings objectAtIndex:[tweetPicker selectedRowInComponent:1]]];
TWTweetComposeViewController *vc = [[TWTweetComposeViewController alloc] init];
[self presentViewController:vc animated:YES completion:nil];
// Show Alert View When The Application Cannot Send Tweets
NSString *message = @”The application cannot send a tweet at the moment. This is because it cannot reach Twitter or you don’t have a Twitter account associated with this device.”;
UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:@”Oops” message:message delegate:nil cancelButtonTitle:@”Dismiss” otherButtonTitles:nil];
Some key points about this code:
1. It checks for internet connectivity and if its not there, app informs the user with a message.
2. The beauty is twitter framework is integrated within iOS, after clicking on send you will see a dialog.
Enjoy and have fun with your Head First book, it is truly a great book.