Restkit request load handler

两盒软妹~` 提交于 2019-12-12 03:34:45

问题


As i see in all RestKit documentations, didWSRequestLoadObjects delegate function is used to handle service response.

The problem is, if I have a different requests (postObject) in my view controller i have to check response type in didWSRequestLoadObjects for each request.

Is there a way to register a function before each postObject and get each response in different function?


回答1:


Which version of RestKit are you using? On the last release it is highly encouraged to use blocks instead of a loadObjects delegate function. For example, the RKObjectManager postObject method has a success and error parameters which receives a block.

Here is an example of use:

RKObjectManager *manager = [RKObjectManager managerWithBaseURL:[NSURL URLWithString:@"http://some.url"];

//Configure here your manager with response descriptors and stuff..

[manager postObject:someObject path:@"/some/path" parameters:nil success:^(RKObjectRequestOperation *operation, RKMappingResult *mappingResult) {
    //Success Response code here
} failure:^(RKObjectRequestOperation *operation, NSError *error) {
    //Error Response code here
}];


来源:https://stackoverflow.com/questions/14473823/restkit-request-load-handler

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