以“/”作为参数的RKRoute不起作用
我试图设置RKRoute从Dropbox API使用RestKit获取文件夹内容。
获取内容的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
但是,然后匹配的path失败[RKPathMather matchesPath:tokenizeQueryStrings:parsedArguments:
因为那里检查斜杠的数量是这样的: RKNumberOfSlashesInString(self.patternString) == RKNumberOfSlashesInString(self.rootPath)
映射的工作,当我注释这个检查,但我相信这是在其他一些情况下需要。
正确的方法是使用2个不同的响应描述符和路由。 斜杠对于RestKit能够正确区分不同的URL,path和模式非常重要。 您可以使用相同的映射,因此它只是另外几行configuration。
我想我find了一个更清洁的解决scheme来解决我的问题:
我configuration我的响应描述符和路线是这样的:
RKResponseDescriptor *rootResponse = [RKResponseDescriptor responseDescriptorWithMapping:dynamicMapping pathPattern:@"metadata/dropbox/:path" keyPath:nil statusCodes:RKStatusCodeIndexSetForClass(RKStatusCodeClassSuccessful)]; RKRoute *route = [RKRoute routeWithClass:[DropboxFolder class] pathPattern:@"metadata/dropbox/:path" method:RKRequestMethodGET]; route.shouldEscapePath = YES; [objectManager.router.routeSet addRoute:route];
现在可以使用1个响应描述符和1个路由。 我不知道这是否适用于其他使用path的API,但它与Dropbox。 (根目录的URL现在是https://api.dropbox.com/1/metadata/dropbox/%2F
)
- 缩放后MKMapview注解dynamicpin图像发生变化
- IBM Worklight – iOS 7状态栏与应用程序的HTML重叠
- 如何在Xcode中创build简单的摄像头覆盖?
- 单元格backgroundColor插入一行时清除奇怪的行为
- 为什么UIButton在button位于UITableViewCell上时显示TouchWhenHighlighted?
- SceneKit相机,如何补偿欧拉规则(方向)的变化
- 在自动布局中,无论方向如何,我怎样才能将视图占用一半的屏幕?
- UIVollectionView与UIViewController作为数据源
- 戴夫·托马斯(Dave Thomas)的数据整理卡塔(Kata)的快速解决方案,第2部分