Making synchronous calls with RestKit

ぃ、小莉子 提交于 2019-12-01 21:04:32

If you need to send synchronously, you're not going to be able to use the convenience methods on RKObjectManager, like putObject, because these convenience methods all send the request asynchronously on your behalf. Instead, you can try something like the following:

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

It can be done using RestKit and the convenience methods on RKObjectManager. The tricks is to use blocks.

In your case you would make your request using the block, set the normal onDidFail, onDidLoadObjects, onDidLoadResponse, etc. methods on "loader" rather than as delegate methods in the class, and then close the app within the block. For example, the code within loader.onDidLoadObjects method will not be executed until the putObject has been completed, so that's likely where you would want to close the screen or app. This would ensure the putObject completes before moving on.

See more in my answer - Make a synchronous HTTP call with RestKit.

what about:

RKRequest *request = [client post:@"/service" params:params delegate:restDelegate];

RKResponse *response = [request sendSynchronously];
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!