我新的restkit和我有一個問題。我有一個休息服務辦理登機手續。所以我打電話給我的休息服務「Put」 - 請求。看起來像Put:http:.../api/v1/locations/location/[Location-ID]/checkin?userId = [User-ID]。答案是一個,所以我稱之爲checkin-object。在我打電話給另一個服務(Get-Request)後檢查。但獲取請求的新映射結果包括先前的簽入對象。我如何重置/刪除它?不正確第二次請求使用休息套件後的迴應
[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!我也嘗試刪除緩存但它沒有工作!
ty,這對我有很大幫助。在編程期間,我忘了設置路徑模式。 – gling