本文介绍了Restkit 请求加载处理程序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

正如我在所有 RestKit 文档中看到的,didWSRequestLoadObjects 委托函数用于处理服务响应.

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

问题是,如果我的视图控制器中有不同的请求 (postObject),我必须在 didWSRequestLoadObjects 中检查每个请求的响应类型.

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.

有没有办法在每个 postObject 之前注册一个函数并在不同的函数中获取每个响应?

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

推荐答案

您使用的是哪个版本的 RestKit?在最后一个版本中,强烈建议使用块而不是 loadObjects 委托函数.例如,RKObjectManager postObject 方法有一个 successerror 参数来接收一个块.

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.

这是一个使用示例:

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

这篇关于Restkit 请求加载处理程序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-17 12:26