我已将 twitter 与我的 iOS 5 应用程序集成在一起,简而言之,推文表工作正常,但每当我点击推文按钮时,它都会显示 twitter 界面,我设法通过不包括 self presentmodalviewcontroller 来摆脱它在代码中,但我找不到自动化推文的方法,因为除非我点击推文表上的发送按钮,否则推文不会发推文。
有没有解决的办法?本质上,我希望我的推文在我点击推文按钮的那一刻被推文,我不想再次点击推文表上的发送按钮?可能的?
编辑:根据下面答案中发布的链接,我浏览了一些 twitter API 示例并在此处找到此代码https://dev.twitter.com/docs/ios/posting-images-using-twrequest 。它工作正常但是当应用程序到达由我说应用程序崩溃的评论标记的部分时崩溃。,错误'NSInvalidARgumentException''数据参数'是零和一堆数字。
此外,我无法使用此行设置帐户,[request setAccount:[self.accounts objectAtIndex:0]];
它给了我一个错误,在“myviewcontrollername”类型的对象上找不到属性帐户
(void)performTWRequestUpload
{
NSURL *url =
[NSURL URLWithString:
@"https://upload.twitter.com/1/statuses/update_with_media.json"];
// Create a POST request for the target endpoint
TWRequest *request =
[[TWRequest alloc] initWithURL:url
parameters:nil
requestMethod:TWRequestMethodPOST];
// self.accounts is an array of all available accounts;
// we use the first one for simplicity
[request setAccount:[self.accounts objectAtIndex:0]];
// The "larry.png" is an image that we have locally
UIImage *image = [UIImage imageNamed:@"larry.png"];
// Obtain NSData from the UIImage
NSData *imageData = UIImagePNGRepresentation(image);
// Add the data of the image with the
// correct parameter name, "media[]"
[request addMultiPartData:imageData
withName:@"media[]"
type:@"multipart/form-data"];
// NB: Our status must be passed as part of the multipart form data
NSString *status = @"just setting up my twttr #iOS5";
// Add the data of the status as parameter "status"
[request addMultiPartData:[status dataUsingEncoding:NSUTF8StringEncoding]
withName:@"status"
type:@"multipart/form-data"];
// Perform the request.
// Note that -[performRequestWithHandler] may be called on any thread,
// so you should explicitly dispatch any UI operations to the main thread
//Problem code part upon reaching which app crashes
[request performRequestWithHandler:
^(NSData *responseData, NSHTTPURLResponse *urlResponse, NSError *error) {
NSDictionary *dict =
(NSDictionary *)[NSJSONSerialization
JSONObjectWithData:responseData options:0 error:nil];
// Log the result
NSLog(@"%@", dict);
dispatch_async(dispatch_get_main_queue(), ^{
// perform an action that updates the UI...
});
}];
}****