我是restkit的新手,我对此有疑问。我有一个登记入住的休息服务。所以我用“Put”请求调用我的休息服务。看起来像这样放:http:.../api/v1/locations/location/[Location-ID]/checkin?userId=[User-ID]。响应是 a ,所以我称它为 checkin-object。签入后即时调用另一个服务(获取请求)。但是获取请求的新映射结果包括先前的签入对象。我如何重置/擦除它?
[self.restHelper checkinUser:[NSNumber numberWithInt:USER_ID] forLocationID:self.selectedLocation success:successBlock failure:failureBlock];
映射:
- (void)checkinUser:(NSNumber*) userID forLocationID:(NSNumber *)locationID success:(void (^)(RKObjectRequestOperation *, RKMappingResult *))success failure:(void (^)(RKObjectRequestOperation *, NSError *))failure{
RKObjectManager *objectManager = [RKObjectManager sharedManager];
RKObjectMapping *userCheckinMapping = [RKObjectMapping mappingForClass:[CheckIN class]];
[userCheckinMapping addAttributeMappingsFromDictionary:@{
@"locationFullname" : @"locationFullname",
@"userNameCityCountry" : @"userNameCityCountry",
@"success" : @"success",
}];
RKResponseDescriptor *responseDescriptor = [RKResponseDescriptor responseDescriptorWithMapping:userCheckinMapping pathPattern:nil keyPath:@"" statusCodes:RKStatusCodeIndexSetForClass(RKStatusCodeClassSuccessful)];
[objectManager addResponseDescriptor:responseDescriptor];
NSString *path = [NSString stringWithFormat:@".../api/v1/locations/location/%@/checkin?userId=%@", locationID,userID];
[objectManager putObject:nil path:path parameters:nil success:^(RKObjectRequestOperation *operation, RKMappingResult *mappingResult) {
success(operation, mappingResult);
} failure:^(RKObjectRequestOperation *operation, NSError *error) {
failure(operation,error);
}];
}
下一个电话是这样的:
-(void)getTracksForLocation:(NSNumber *)locationID withType:(NSString*) type success:(void (^)(RKObjectRequestOperation *, RKMappingResult *))success failure:(void (^)(RKObjectRequestOperation *, NSError *))failure{
RKObjectManager *objectManager = [RKObjectManager sharedManager];
RKObjectMapping *trackResultsMapping = [RKObjectMapping mappingForClass:[RESTTracksResult class]];
[trackResultsMapping addAttributeMappingsFromDictionary:@{
@"id" : @"ID",
@"cued" : @"cued",
@"marked" : @"marked",
@"playing": @"playing",
@"played": @"played",
@"creditBidSum": @"creditBidSum",
}];
RKObjectMapping *trackMapping = [RKObjectMapping mappingForClass:[RESTTrack class]];
[trackMapping addAttributeMappingsFromDictionary:@{
//@"id" : @"ID",
@"name" : @"name",
@"artistName" : @"artistName",
@"genre": @"genre",
@"length": @"length",
}];
RKRelationshipMapping* relationShipMapping = [RKRelationshipMapping relationshipMappingFromKeyPath:@"track"
toKeyPath:@"track"
withMapping:trackMapping];
[trackResultsMapping addPropertyMapping:relationShipMapping];
RKResponseDescriptor *responseDescriptor = [RKResponseDescriptor responseDescriptorWithMapping:trackResultsMapping pathPattern:nil keyPath:@"results" statusCodes:RKStatusCodeIndexSetForClass(RKStatusCodeClassSuccessful)];
[objectManager addResponseDescriptor:responseDescriptor];
NSDictionary *trackDictionary = @{ @"type": type};
NSString *path = [NSString stringWithFormat:@".../api/v1/locations/location/%@/tracks", locationID ];
[objectManager getObjectsAtPath:path parameters:trackDictionary success:^(RKObjectRequestOperation *operation, RKMappingResult *mappingResult) {
success(operation, mappingResult);
} failure:^(RKObjectRequestOperation *operation, NSError *error) {
failure(operation,error);
}];
}
希望你能帮助我,泰!我也试过删除缓存,但没有用!