我正在尝试设置 RKRoute 以使用 RestKit 从 Dropbox API 获取文件夹内容。
获取内容的URL是https://api.dropbox.com/1/metadata/dropbox/<path>
.
所以我这样设置响应和路由:
// objectManagers baseURL is @"https://api.dropbox.com/1/"
RKResponseDescriptor *rootResponse = [RKResponseDescriptor responseDescriptorWithMapping:dynamicMapping pathPattern:@"metadata/dropbox:path" keyPath:nil statusCodes:RKStatusCodeIndexSetForClass(RKStatusCodeClassSuccessful)];
[objectManager.router.routeSet addRoute:[RKRoute routeWithClass:[DropboxFolder class] pathPattern:@"metadata/dropbox:path" method:RKRequestMethodGET]];
// dropboxFolder.path is @"/" for root
// dropboxFolder.path is @"/Images" for the "Images"-folder contained in root
但是在 [RKPathMather matchesPath:tokenizeQueryStrings:parsedArguments:
中路径匹配失败了因为斜杠的数量是这样检查的:RKNumberOfSlashesInString(self.patternString) == RKNumberOfSlashesInString(self.rootPath)
当我注释掉此检查时,映射有效,但我确定在其他一些情况下需要它。
最佳答案
正确的方法是使用 2 个不同的响应描述符和路由。斜杠对于让 RestKit 正确区分不同的 URL、路径和模式很重要。您可以使用相同的映射,因此它“只是”另外几行配置。
关于ios - 以 "/"作为参数的 RKRoute 不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16690770/