【问题标题】:RestKit issue after upgrading to 0.22升级到 0.22 后的 RestKit 问题
【发布时间】:2013-12-13 18:11:56
【问题描述】:

我最近将 RestKit 从 0.20.3 更新到了 0.22 版本。 我更新了日期格式化程序等,除了两个 URL 之外一切正常。

现在我的两个 POST 请求找不到响应描述符。 我有一个“没有响应描述符匹配加载的响应”错误,列出了我的 RKObjectManager 上的每个响应描述符。特别是以下行:

<RKResponseDescriptor: 0x1edf4f00 baseURL=https://mybaseurl/ pathPattern=transfer/execute statusCodes=200-299> failed to match: response path 'transfer/execute' did not match the path pattern 'transfer/execute'.  

有人可以指导我找到我可能错过的迁移指南吗? 如果我调试在它试图找到响应描述符的地方放置断点,然后我转到- (BOOL)gatherParameterValues:(NSArray**)pValues fromString:(NSString *)string,我会得到传输/执行的“是”,所以我真的不知道它在哪里中断。

似乎 RKMapperOperation 上的 mappingsDictionary 在主要方法中为空...

编辑

// POST Requests
#pragma mark [POST] transfer/execute
    {
        // execute transfer
        NSString *pathPattern = @"transfer/execute";

        // route
        [manager.router.routeSet
         addRoute:[RKRoute routeWithClass:[Transfer class]
                              pathPattern:pathPattern
                                   method:RKRequestMethodPOST]];

        // request
        RKMapping *requestMapping = [self.mappingProvider transferMapping];
        RKRequestDescriptor *requestDescriptor = [RKRequestDescriptor
                                                  requestDescriptorWithMapping:requestMapping
                                                  objectClass:[Transfer class]
                                                  rootKeyPath:nil
                                                  method:RKRequestMethodPOST];
        [manager addRequestDescriptor:requestDescriptor];

        // response
        RKMapping *responseMapping = [self.mappingProvider transferResultMapping];
        RKResponseDescriptor *responseDescriptor = [RKResponseDescriptor
                                                    responseDescriptorWithMapping:responseMapping
                                                    method:RKRequestMethodGET
                                                    pathPattern:pathPattern
                                                    keyPath:nil
                                                    statusCodes:statusCodesSuccess];
        [manager addResponseDescriptor:responseDescriptor];
    }

【问题讨论】:

  • 你能显示你的响应描述符的代码吗?您是否更新了已弃用的方法?
  • 是的,我对已弃用的方法没有任何警告,我将代码更改为使用值转换器。

标签: objective-c restkit restkit-0.20


【解决方案1】:

您的响应描述符具有method:RKRequestMethodGET,因此在您发出 POST 请求时不会考虑它。将其更改为RKRequestMethodPOSTRKRequestMethodAny

【讨论】:

  • 天啊...我再也不会复制和粘贴代码了。它解释了我的其他奇怪行为。非常感谢。
  • 这是否意味着 RestKit 0.20.3 对响应描述符更加宽容?
  • responseDescriptorWithMapping:method:pathPattern:keyPath:statusCodes: 是一种相当新的方法,因此将响应描述符限制为特定方法是一个相对较新的功能。不推荐使用的方法默认为Any。我认为只要该方法存在,过滤就已完全实现。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2018-12-31
  • 2020-06-24
  • 2019-01-02
  • 2014-08-17
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多