使用RestKit进行同步HTTP调用

当将用户login到我的应用程序中时,我需要仅使用用户名从服务器拉下用户对象。 这将返回userId(除其他外),以​​便进行其他API调用。 从那一刻起,我将使用userId进行一些其他的HTTP调用。 在发送其他呼叫之前,如何使同步呼叫完全拉下用户对象?

我已经在我的应用程序委托类中设置了我的对象映射,它完美地工作,并使用此代码从服务器拉下用户对象:

[[RKObjectManager sharedManager] loadObjectsAtResourcePath:[@"/api/users/" stringByAppendingString:[_userNameField text]] delegate:self]; 

这就是我已经尝试过…这里build议: 使用RestKit进行同步调用

 RKObjectLoader* loader = [[RKObjectManager sharedManager] objectLoaderForObject:currentUser method:RKRequestMethodPUT delegate:nil]; RKResponse* response = [loader sendSynchronously]; 

然而,这个代码(1)使用了不赞成使用的方法objectLoaderForObject,并且(2)崩溃说'Unable to find a routable path for object of type '(null)' for HTTP Method 'POST''

撇开这是否是iPhone应用程序的理想devise的问题,我能够完成我希望使用块的东西。

 [[RKObjectManager sharedManager] loadObjectsAtResourcePath:[@"/api/users/" stringByAppendingString:[_userNameField text]] usingBlock:^(RKObjectLoader* loader) { loader.onDidLoadResponse = ^(RKResponse *response) { NSLog(@"Response: \n%@", [response bodyAsString]); }; loader.onDidLoadObjects = ^(NSArray *objects) { APIUser *apiUser = [objects objectAtIndex:0]; NSLog(@"user_id is %i", apiUser.user_id); }; loader.onDidFailWithError = ^(NSError *error) { UIAlertView *badLoginAlert = [[UIAlertView alloc]initWithTitle:NSLocalizedString(@"LOGIN_FAILED", nil) message:NSLocalizedString(@"BAD PASSWORD OR USERNAME", nil) delegate:self cancelButtonTitle:NSLocalizedString(@"OK", nil) otherButtonTitles:nil]; [badLoginAlert show]; }; }]; 

希望这有助于某人。