简体   繁体   English

RestKit iOS应用程序根据请求崩溃

[英]RestKit iOS application crashes on request

i have a big Problem with Objective C and RestKit. 我对Objective C和RestKit有一个很大的问题。 On application startup i want to click a Button. 在应用程序启动时,我想单击一个按钮。 But if i click the button instantly after the startup my application crashes. 但是,如果我在启动后立即单击按钮,我的应用程序崩溃了。 If i wait a few seconds everything works fine. 如果我等待几秒钟,一切正常。

Anyone an idea? 有人有想法吗? That's my code 那是我的代码

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

The client will be created in de "AppDelegate" after startup 启动后,客户端将在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;

The 'sendRequest' Methode will be called after i pressed the button. 按下按钮后,将调用'sendRequest'Methode。

Sorry, my english isn't very good. 对不起,我的英语不是很好。 I hope you understood my problem. 我希望你理解我的问题。

I have exectly the same problem.. Able to fix this with blocks 我有完全相同的问题..能够用块解决这个问题

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM