【问题标题】:issue with EXC_BAD_REQUEST in TWRequestTWRequest 中的 EXC_BAD_REQUEST 问题
【发布时间】:2012-01-10 04:52:49
【问题描述】:

我有以下代码,它在执行请求时总是让我崩溃,知道吗?

NSString *responseBody = [[NSString alloc] initWithData:data
                                                       encoding:NSUTF8StringEncoding];

        NSLog(@"Response body is %@", responseBody);

        NSDictionary *accessTokenRequestParams = [[NSMutableDictionary alloc] init];
        [accessTokenRequestParams setValue:CONSUMER_KEY forKey:@"x_reverse_auth_target"];
        [accessTokenRequestParams setValue:responseBody forKey:@"x_reverse_auth_parameters"];            

        NSURL *url2 = [NSURL URLWithString:@"https://api.twitter.com/oauth/access_token"];
        TWRequest * accessTokenRequest = [[TWRequest alloc] initWithURL:url2 parameters:accessTokenRequestParams requestMethod:TWRequestMethodPOST];


        if (selectionIndex != -1)
            [accessTokenRequest setAccount:[self.twitterACAccounts objectAtIndex:selectionIndex]];

        // execute the request
        [accessTokenRequest performRequestWithHandler:
         ^(NSData *responseData, NSHTTPURLResponse *urlResponse, NSError *error) {
             NSString *responseStr = 
             [[NSString alloc] initWithData:responseData 
                                   encoding:NSUTF8StringEncoding];

            NSLog(@"The user's info for your server:\n%@", responseStr);
         }];

更新: 打开 NSZombieEnabled 给我

*** -[ACAccountStore typeForAccount:]: message sent to deallocated instance 0x7199c70

这里找不到了

【问题讨论】:

  • 尝试设置一个异常断点,然后准确地发布它在哪一行中断以及抛出什么异常。
  • 请在块(//执行请求)代码上放置断点并找出哪一行给您带来问题。

标签: iphone objective-c ios ipad twrequest


【解决方案1】:

您的错误看起来与您的问题完全不同。您在 ACAccountStore 类中有错误。在您访问、操作和存储帐户 (ACAccountStore) 时检查您的保留计数。我认为您首先被释放了内存,并且您正在使用某些地方。

【讨论】:

    【解决方案2】:

    您在某处调用 ACAccountStore typeForAccount。但是 ACAccountStore 不见了。查看 AccountAccount 文档,没有特殊的初始化程序,因此您的代码中可能有类似的内容:

    static ACAccountStore* accountStore = [[[ACAccountStore alloc] init] autorelease];
    

    然后在请求完成时,对象已被操作系统清除,但您的 accountStore 仍指向旧的、现在悬空的指针。指针可能是“静态”或“全局”,或者是其他静态或全局对象的成员。

    在您的代码中查找 ACAccountStore。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2012-09-05
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-08-10
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多