【问题标题】:TWRequest performRequestWithHandler no error, but nothing happenTWRequest performRequestWithHandler 没有错误,但是什么也没发生
【发布时间】:2012-09-10 03:11:09
【问题描述】:

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

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

                }];
            }
        }

谁能帮帮我?

谢谢

【问题讨论】:

  • 这也开始发生在我身上。出于某种原因,在 iPod touch iOS5 上它可以正常工作,但在 iPhone 4 iOS6 上却不行。检查 URL 是否正确:https://api.twitter.com/1.1/statuses/update_with_media.jsonhttps://upload.twitter.com/1/statuses/update_with_media.json

标签: ios twitter request twrequest


【解决方案1】:

现在在 iOS 中发送推文非常容易。昨晚我更新了我的应用程序,不再使用旧技术,而是使用新的 SLComposeViewController 技术。下面是我的应用程序中的一个 sn-p 代码,它允许用户发送带有附加图像的推文。基本上完全相同的代码可用于发布到 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");
    }

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2017-02-13
    • 1970-01-01
    • 2012-09-14
    • 1970-01-01
    • 2019-09-20
    • 2017-09-03
    • 1970-01-01
    相关资源
    最近更新 更多