1

I am trying to addRoutes but getting "Cannot add a route with the same class and method as an existing route."

I have a class Thing that has the same route method for Post, but with a different method of course. When I try to run my app I get the above error. Is there a way to setup the route with a generic method?

[objectManager.router.routeSet addRoute:[RKRoute routeWithClass:[Thing class]
                                                    pathPattern:@"v1/things/update_location.json.json" method:RKRequestMethodPOST]];

[objectManager.router.routeSet addRoute:[RKRoute routeWithClass:[Thing class]
                                                    pathPattern:@"v1/things.json" method:RKRequestMethodPOST]];

The above is a duplicate according to Restkit, as it using the same class "Thing" and because the Method is the same? What gives?

4

2 回答 2

2

如果它可以帮助任何人使用代码,这里是如何设置带有名称的路线。

// When you are setting up your mapping, set up Route with Name.
RKResponseDescriptor *responseDescriptor = [RKResponseDescriptor responseDescriptorWithMapping:userMapping
                                                                                            method:RKRequestMethodGET
                                                                                       pathPattern:LOGIN_URL
                                                                                           keyPath:nil
                                                                                       statusCodes:RKStatusCodeIndexSetForClass(RKStatusCodeClassSuccessful)];
[[RKObjectManager sharedManager].router.routeSet addRoute:[RKRoute routeWithName:LOGIN_ROUTE pathPattern:LOGIN_URL method:RKRequestMethodGET]];
[[RKObjectManager sharedManager] addResponseDescriptor:responseDescriptor];


// And when you are ready to make the http call, do the following
[[RKObjectManager sharedManager] getObjectsAtPathForRouteNamed:LOGIN_ROUTE
                                                        object:userProfile
                                                    parameters:params
                                                       success:success
                                                       failure:failure];
于 2014-04-10T18:15:36.670 回答
1

Thing当给定一个对象(在这种情况下是一个实例)时,路由器用于构建请求。为此,当您要求 RestKit 发布对象时,只能选择一个选项。任何其他路由都需要用命名路由或关系路由来描述,以保持路由集的唯一性。

您可以在此处查看文档,它描述了“路由生成”部分中定义路由器的所有 3 种方法(您目前仅使用方法 2)。您很可能想要定义一些命名路由,这些路由描述了您尝试通过每次上传实现的目标之间的差异。

于 2013-04-21T23:07:24.000 回答