【问题标题】:RestKit iOS application crashes on requestRestKit iOS 应用程序应请求崩溃
【发布时间】:2012-11-01 17:14:53
【问题描述】:

我对 Objective C 和 RestKit 有一个大问题。 在应用程序启动时,我想单击一个按钮。 但是如果我在启动后立即单击按钮,我的应用程序就会崩溃。 如果我等待几秒钟,一切正常。

任何人的想法? 这是我的代码

- (void)sendRequest {
// Perform a simple HTTP GET and call me back with the results
[[RKClient sharedClient] get:@"/user" delegate:self];
}

- (void)request:(RKRequest*)request didLoadResponse:(RKResponse*)response {
  if ([response isSuccessful]) {
    NSLog(@"HTTP status code:     %d", response.statusCode);
    NSLog(@"HTTP status message:  %@", [response localizedStatusCodeString]);
  }
}

客户端启动后会在“AppDelegate”中创建

RKClient *client = [RKClient clientWithBaseURLString:@"http://192.168.0.6:8080"];
[client setPassword:@"user"];
[client setUsername:@"user"];
[client setAuthenticationType:RKRequestAuthenticationTypeHTTPBasic];
client.requestQueue.showsNetworkActivityIndicatorWhenBusy = YES;

'sendRequest' 方法将在我按下按钮后被调用。

对不起,我的英语不是很好。 我希望你能理解我的问题。

【问题讨论】:

  • 调试器输出为: (lldb) 它跳转到 RKResponse.m - if ([[_request delegate] respondsToSelector:@selector(request:didReceiveResponse:)]) { - 并说“线程 1: EXC_BAD_ACCESS(代码=1,地址=0xc0000008)

标签: objective-c ios crash ios6 restkit


【解决方案1】:

我也有同样的问题.. 可以用积木解决这个问题

NSURL *baseURL = [[NSURL alloc] initWithString:@"http://your.api.com"];
RKClient *client = [RKClient clientWithBaseURL:baseURL];

RKRequest *request = [client get:@"/method/name" queryParameters:nil delegate:nil];
request.onDidLoadResponse = ^(RKResponse *response) {
    NSLog(@"%@", [response bodyAsString]);
};

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2018-01-26
    • 2021-03-05
    • 2014-11-23
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-07-05
    • 1970-01-01
    相关资源
    最近更新 更多