我有一个项目,当我的 RestEngine 类建立时,我正在设置所有 responseDescriptors(其中 8 个)和映射(其中 8 个)......我提前设置它们,而不是在每次调用期间。我不确定这是否是好的做法。
问题是我的一个描述符似乎在不应该映射所有结果。
我认为问题在于我的 thingDescriptor 或者它可能是以下路线(v1/things/:thingID\.json),但这条路线是 GET,所以我认为我的 POST 请求不会通过这条路线?
这是我正在发出的 POST 请求,该请求将结果映射到不应该的特定类,或者我不希望它映射到特定类。
[[RKObjectManager sharedManager] postObject:nil
path:@"v1/things/request.json"
parameters:@{
@"auth_token" : self.accessToken,
@"api_key" : self.api_key,
@"lat" : lat,
@"lng" : lng
}
success:^(RKObjectRequestOperation *operation, RKMappingResult *mappingResult) {
RKLogInfo(@"Post request of an Thing Request start tracking request update...");
<-- the mappingResult shows its mapped to a Thing class but I want server response to mapped to an NSDictionary instead?
}
failure:^(RKObjectRequestOperation *operation, NSError *error) {
RKLogError(@"Post request of an Thing Request failed with error: %@", error);
}];
这是我设置的映射:
// Routes for Things
[objectManager.router.routeSet addRoute:[RKRoute routeWithClass:[Thing class]
pathPattern:@"v1/things/:thingID\\.json"
method:RKRequestMethodGET]];
[objectManager.router.routeSet addRoute:[RKRoute routeWithName:kRouteUpdateThingLoc
pathPattern:@"v1/things/update_location.json"
method:RKRequestMethodPOST]];
[objectManager.router.routeSet addRoute:[RKRoute routeWithClass:[Thing class]
pathPattern:@"v1/things.json"
method:RKRequestMethodPOST]];
// Register our mappings with the provider
RKResponseDescriptor *thingResponseDescriptor = [RKResponseDescriptor responseDescriptorWithMapping:thingMapping
pathPattern:@"v1/things.json"
keyPath:nil
statusCodes:RKStatusCodeIndexSetForClass(RKStatusCodeClassSuccessful)];
RKResponseDescriptor *thingDescriptor = [RKResponseDescriptor responseDescriptorWithMapping:thingMapping
pathPattern:@"v1/things/:thingID.json"
keyPath:nil
statusCodes:RKStatusCodeIndexSetForClass(RKStatusCodeClassSuccessful)];