Tôi đã tìm thấy và sử dụng rất nhiều câu trả lời tuyệt vời trên trang này, Cảm ơn mọi người, nghĩ đã đến lúc trả lại :). và văn bản trên một tweet bằng TWRequest ...
TWRequest *postRequest = [[TWRequest alloc] initWithURL:[NSURL URLWithString:@"https://upload.twitter.com/1/statuses/update_with_media.json"] parameters:nil requestMethod:TWRequestMethodPOST];
UIImage * image = [UIImage imageNamed:@"myImage.png"];
//add text
[postRequest addMultiPartData:[@"I just found the secret level!" dataUsingEncoding:NSUTF8StringEncoding] withName:@"status" type:@"multipart/form-data"];
//add image
[postRequest addMultiPartData:UIImagePNGRepresentation(image) withName:@"media" type:@"multipart/form-data"];
// Set the account used to post the tweet.
[postRequest setAccount:twitterAccount];
// Perform the request created above and create a handler block to handle the response.
[postRequest performRequestWithHandler:^(NSData *responseData, NSHTTPURLResponse *urlResponse, NSError *error) {
NSString *output = [NSString stringWithFormat:@"HTTP response status: %i", [urlResponse statusCode]];
[self performSelectorOnMainThread:@selector(displayText:) withObject:output waitUntilDone:NO];
}];
tôi thấy sử dụng TWRequest là giải pháp tốt nhất cho kịch bản của tôi vì tôi không muốn người dùng có thể chỉnh sửa bài viết trước khi tweet (mà là vấn đề với việc sử dụng TWTweetComposeViewController)
Mã này có áp dụng trong chỉ ios5 không? hoặc tôi có thể sử dụng nó cho các phiên bản thấp hơn chỉ – iPhone
iOS5, có thư viện twitter mở ra có thể giúp bạn nếu bạn cần một giải pháp
staticfiction
Bạn có thể làm điều tương tự trong iOS 4 với [DETweetComposeViewController] (https://github.com/ doubleencore/DETweetComposeViewController). –