我正在尝试在iOS 5上使用Twitter Framework进行分享 用户将选择要使用的帐户,因此应用将使用所选帐户进行共享。
但是,当performRequestWithHandler
返回error
null
的分享传递给for (int i = 0; i < [_accountsArray count]; i++) {
//searching for a selected account
if ([[[_accountsArray objectAtIndex:i] username] isEqualToString:[self getUserName]]) {
actualUser = [_accountsArray objectAtIndex:i];
TWRequest *sendTweet = [[TWRequest alloc] initWithURL:[NSURL URLWithString:@"https://upload.twitter.com/1/statuses/update_with_media.json"]
parameters:nil
requestMethod:TWRequestMethodPOST];
[sendTweet addMultiPartData:[text dataUsingEncoding:NSUTF8StringEncoding] withName:@"status" type:@"multipart/form-data"];
ACAccountStore *account = [[ACAccountStore alloc] init];
[sendTweet setAccount:[account.accounts objectAtIndex:i]];
NSLog(@"%@",sendTweet.account);
[sendTweet performRequestWithHandler:^(NSData *responseData, NSHTTPURLResponse *urlResponse, NSError *error) {
NSLog(@"responseData: %@\n", responseData);
NSLog(@"urlResponse: %@\n", urlResponse);
NSLog(@"error: %@",error);
}];
}
}
我的代码:
{{1}}
任何人都可以帮助我吗?
由于
答案 0 :(得分:1)
现在在iOS上发送推文非常容易。昨晚我更新了我的应用程序,不再使用旧技术,而是使用新的SLComposeViewController技术。下面是我在我的应用程序中的代码片段,允许用户发送带有附加图像的推文。基本上完全相同的代码可用于发布到Facebook。请尝试使用此代码。它还应该允许用户选择他们发送推文的帐户(我也相信这个“默认帐户”发送设置隐藏在电话的设置中)。
if ([SLComposeViewController isAvailableForServiceType:SLServiceTypeTwitter]) {
SLComposeViewController *mySLComposerSheet = [SLComposeViewController composeViewControllerForServiceType:SLServiceTypeTwitter];
[mySLComposerSheet setInitialText:@"Sample Tweet Text"];
//Add the image the user is working with
[mySLComposerSheet addImage:self.workingImage];
//Add a URL if desired
//[mySLComposerSheet addURL:[NSURL URLWithString:@"http://google.com"]];
//Pop up the post to the user so they can edit and submit
[self presentViewController:mySLComposerSheet animated:YES completion:nil];
//Handle the event
[mySLComposerSheet setCompletionHandler:^(SLComposeViewControllerResult result) {
switch (result) {
case SLComposeViewControllerResultCancelled:
NSLog(@"Tweet Canceled");
case SLComposeViewControllerResultDone:
NSLog(@"Tweet Done");
break;
default:
break;
}
}];
} else {
//Can't send tweets, show error
NSLog(@"User doesn't have twitter setup");
}