RestKit - 未触发RkObjectManager回调方法

时间:2012-08-17 17:54:06

标签: iphone objective-c ios restkit

我是iOS开发的新手。我想使用RestKit访问Web服务并将数据映射到我的自定义对象。

我确信正在达到搜索方法。但是,没有触发任何回调方法(didLoadObjects或didFailWithError)。我的代码如下。谢谢你的帮助!

编辑:我尝试使用简单的RKClient请求执行相同操作,并且也未触发这些回调方法。我还实现了“观察请求进度”方法,并且也没有触发这些方法。我没有正确分配代表吗?

编辑2:看起来这个请求可能会卡在队列中。如果我强制它以异步方式发送,则会触发方法“requestWillPrepareForSend”和“requestDidStartLoad”。没有其他方法被触发。

- (void)search{

NSString *baseURL = @"sws.acpl.lib.in.us:8080/symws/rest/";
NSURL *url=[NSURL URLWithString:baseURL];

RKObjectManager *manager=[RKObjectManager objectManagerWithBaseURL:url];

RKObjectMapping *availabilityMapping = [RKObjectMapping mappingForClass:[TitleAvailabilityInfo class]];

[availabilityMapping mapAttributes:@"totalAvailableCopies", @"holdable", nil];

RKObjectMapping *titleMapping = [RKObjectMapping mappingForClass:[SearchResultsTitle class]];
[titleMapping mapAttributes:@"titleID",@"title",@"author",@"materialType",@"yearOfPublication",@"ISBN",@"callNumber", nil];
[titleMapping mapKeyPath:@"TitleAvailabilityInfo" toRelationship:@"titleAvailabilityInfo" withMapping:availabilityMapping];

RKObjectMapping *searchResponseMapping = [RKObjectMapping mappingForClass:[SearchCatalogResponse class]];
[searchResponseMapping mapAttributes:@"queryID",@"totalHits",@"firstHitDisplayed",@"lastHitDisplayed", nil];
[searchResponseMapping mapKeyPath:@"HitlistTitleInfo" toRelationship:@"results" withMapping:titleMapping];



[manager.mappingProvider setMapping:searchResponseMapping    forKeyPath:@"SearchCatalogResponse"];

[manager loadObjectsAtResourcePath:@"standard/searchCatalog" delegate:self];

}

- (void)objectLoader:(RKObjectLoader*)objectLoader didLoadObjects:(NSArray*)objects {

NSLog(@"loaded");
}

- (void)objectLoader:(RKObjectLoader*)objectLoader didFailWithError:(NSError*)error {
NSLog(@"failed");
}

1 个答案:

答案 0 :(得分:0)

问题在于网址。我在开头就离开了“http://”。谢谢你的帮助。