RESTKIT iOS应用程序应要求崩溃



我在目标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]);
  }
}

启动之后,将在de" 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" methode。

对不起,我的英语不是很好。希望您了解我的问题。

我有同样的问题。能够用块修复

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]);
};

最新更新