내가 Restkit에 새로 왔는데 그 문제가 있습니다. 나는 체크 인을 위해 restservice를 가지고있다. 그래서 나는 "Put"-request로 나의 restservice를 부른다. http : .../api/v1/locations/location/[위치 ID]/checkin? userId = [사용자 ID]와 같이 표시됩니다. 응답은 A입니다. 그래서 나는 그것을 checkin-object라고 부릅니다. 체크인 후 다른 서비스 (Get-Request)를 호출합니다. 그러나 get-request의 새 매핑 결과에는 이전 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);
}];
}
잘하면 당신이 나를 도울 수, 타이! 또한 캐시를 삭제하려고 시도했지만 작동하지 않았습니다!
ty, 저에게 많은 도움이되었습니다. 프로그래밍하는 동안 경로 패턴을 설정하는 것을 잊었습니다. – gling