Reputation: 23
I'm creating an application that has integration with Twitter .. and wanted to know what have to do to create a button to add an image of the device in the tweet.and also wanted to know which framework to use it and also where the code
Upvotes: 1
Views: 1438
Reputation: 15661
You can just use the twitter framework, it's included since iOS 5
And the code i use:
- (IBAction)twitter:(id)sender {
if([TWTweetComposeViewController canSendTweet])
{
NSLog(@"Ready to Tweet.");
TWTweetComposeViewController *tweetComposer = [[TWTweetComposeViewController alloc] init];
[tweetComposer setInitialText:[NSString stringWithFormat:@"My message"]];
[tweetComposer addImage:[UIImage imageNamed:@"114x114"]];
[tweetComposer addURL:[NSURL URLWithString:@"http://myPage"]];
tweetComposer.completionHandler = ^(TWTweetComposeViewControllerResult result){
if(result == TWTweetComposeViewControllerResultDone){
NSLog(@"Tweeted.");
} else if(result == TWTweetComposeViewControllerResultCancelled) {
NSLog(@"Cancelled.");
}
[self.navigationController dismissViewControllerAnimated:YES completion:nil];
};
[self presentModalViewController:tweetComposer animated:YES];
}else {
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Oops"
message:@"You can't send a tweet right now, make sure your device has an internet connection and you have at least one Twitter account setup"
delegate:nil
cancelButtonTitle:@"OK"
otherButtonTitles:nil];
[alert show];
[alert release];
}
}
Upvotes: 2