Restkit request load handler

2019-09-07 18:09发布

问题:

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
}];