我正在创建一个与 Twitter 集成的应用程序 .. 并且想知道如何创建一个按钮以在推文中添加设备的图像。还想知道使用哪个框架以及在哪里代码
问问题
1430 次
1 回答
2
你可以只使用 twitter 框架,它从 iOS 5 开始就包含了
我使用的代码:
- (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];
}
}
于 2012-10-11T05:02:08.500 回答