jjzjj

ios - TWRequest performRequestWithHandler 没有错误,但没有任何反应

coder 2023-09-30 原文

我正在尝试使用 iOS 5 上的 Twitter 框架进行分享 用户将选择要使用的帐户,因此该应用将使用所选帐户进行共享。

但是当 share 传递给 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);

                }];
            }
        }

谁能帮帮我?

谢谢

最佳答案

现在在 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");
    }

关于ios - TWRequest performRequestWithHandler 没有错误,但没有任何反应,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12467110/

有关ios - TWRequest performRequestWithHandler 没有错误,但没有任何反应的更多相关文章

随机推荐