我正在努力获得与元数据的正确映射......除了元数据url参数外,所有内容都完美映射。
这是我的实体映射:
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) {
}];
我也试过混合各种Routes和getObjectsAt等......
问候,阿德里安。
答案 0 :(得分: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) {
}];
Eh并不知道它的运作方式。