I have an ARC-enabled project using RestKit and although most of my requests are done asynchronously, I am having an issue with performing a synchronous request:
In my AppDelegate:
else if (![IKUserController loggedInUserIsAuthenticated]) {
IKLoginViewController *loginVC = [[IKLoginViewController alloc] init];
loginVC.scenario = SCENARIO_EXISTING;
[self.window.rootViewController presentModalViewController:loginVC animated:YES];
}
In the implementation for loggedInUserIsAuthenticated:
+ (BOOL)loggedInUserIsAuthenticated {
IKUser *user = [IKUserController loggedInUser];
if (!user) {
return NO;
}
else {
NSString *username = user.userName;
NSString *password = user.userPassword;
if ([IKUserController loginWithUsername:username password:password]) {
return YES;
}
else {
return NO;
}
}
return NO;
}
and the loginWithUserName:password:
+ (BOOL)loginWithUsername:(NSString *)username password:(NSString *)password {
//return YES;
NSDictionary *params = [[NSDictionary alloc] initWithObjectsAndKeys:username, @"username", password, @"password", nil];
RKResponse *response = [[[RKClient sharedClient] post:@"/user/authenticate" params:params delegate:nil] sendSynchronously];
if (response.isOK) {
return YES;
}
else {
return NO;
}
return NO;
}
and the error:
*** Assertion failure in -[RKRequestQueue removeRequest:decrementCounter:], /Users/admin/Documents/dev/RestKit/Code/Network/RKRequestQueue.m:350
The RKClient method post already adds the request to the default request queue, so I think the problem is that you send the request twice – once async and once sync. Instead of using RKClient post method, configure the request manually. There is a method setupRequest on RKClient, this will make it easier for you and you will only need to define the url, method and params, like this: