2016-01-20 98 views
0

我努力得到正確的元數據映射......除了元數據url參數以外,一切都完美映射。Restkit元數據不映射

這裏是我的實體映射:

RKEntityMapping *statisticsMapping = [RKEntityMapping mappingForEntityForName:@"Statistics" inManagedObjectStore:managedObjectStore]; 
[statisticsMapping addAttributeMappingsFromArray:@[@"fromDate", @"toDate", @"visits", @"newVisits"]]; 
[statisticsMapping addAttributeMappingsFromDictionary:@{ 
                 @"@metadata.routing.parameters.randomId" : @"applicationRandomId" 
                 }]; 
[statisticsMapping addConnectionForRelationship:@"application" connectedBy:@"applicationRandomId"]; 

響應描述:

RKResponseDescriptor *ststResp = [RKResponseDescriptor responseDescriptorWithMapping:statisticsMapping 
                         method:RKRequestMethodGET 
                        pathPattern:@"api/apps/:randomId/statistics" 
                         keyPath:@"details" 
                        statusCodes:RKStatusCodeIndexSetForClass(RKStatusCodeClassSuccessful)]; 

路由:

[objectManager.router.routeSet addRoute:[RKRoute routeWithClass:[Statistics class] pathPattern:@"api/apps/:randomId/statistics" method:RKRequestMethodGET]]; 

我該如何讓他們:

NSString *url = [NSString stringWithFormat:@"/api/apps/%@/statistics",applicationRandomId]; 
NSMutableURLRequest *statistics = [[RKObjectManager sharedManager] requestWithObject:@"Statistics" method:RKRequestMethodGET path:url parameters:@{ 
                                         @"fromDate" : @"01-01-2016", 
                                         @"toDate" : @"20-01-2016" 
                                         }]; 

RKObjectRequestOperation *operation = [[RKObjectManager sharedManager] managedObjectRequestOperationWithRequest:statistics managedObjectContext:[RKManagedObjectStore defaultStore].mainQueueManagedObjectContext success:^(RKObjectRequestOperation *operation, RKMappingResult *mappingResult) {  

} failure:^(RKObjectRequestOperation *operation, NSError *error) { 

}]; 

我也嘗試過與各種路由和getObjectsAt等混合...

阿德里安。

回答

0

解決方案:

[objectManager.router.routeSet addRoute:[RKRoute routeWithName:@"statistics" pathPattern:@"api/apps/:randomId/statistics" method:RKRequestMethodGET]]; 

[[RKObjectManager sharedManager] getObjectsAtPathForRouteNamed:@"statistics" object:@{@"randomId" : applicationRandomId} parameters:nil 
                            } success:^(RKObjectRequestOperation *operation, RKMappingResult *mappingResult) { 

                            } failure:^(RKObjectRequestOperation *operation, NSError *error) { 

                            }]; 

呃不知道它的工作的方式。