Reputation: 11
i have a big Problem with Objective C and 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
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.
Sorry, my english isn't very good. I hope you understood my problem.
Upvotes: 1
Views: 309
Reputation: 31
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]);
};
Upvotes: 3