2013-04-21 46 views
1

我想添加路线但获得“无法添加具有与现有路线相同类别和方法的路线。”无法添加与现有路线具有相同类别和方法的路线

我有一个类的东西有相同的邮政路线方法,但当然有不同的方法。当我尝试运行我的应用程序时,出现上述错误。有没有办法用通用方法设置路线?

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

上面是一个重复根据Restkit,作为使用相同的类“物”,并且因为方法是相同的吗?是什么赋予了?

回答

1

路由器用于在给定对象时创建请求(本例中为Thing的实例)。对于这个工作,当你要求RestKit发布一个对象时,只能有一个选择。任何其他路由都需要使用命名路由或关系路由来描述,以维护路由集合的唯一性。

您可以查看文档here,它描述了'路由生成'部分中定义路由器的所有3种方法(您目前只使用方法2)。很可能你想定义一些命名路线来描述你试图实现每次上传的区别。

+0

对不起,但我不确定最后一句话的含义。你有什么例子吗? – jdog 2013-04-22 02:45:49

1

万一它帮助任何人的代码,继承人如何设置与名称的路线。

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