我正在使用RestKit连接我们的WCF数据服务。使用RKObjectManager的postObject函数添加实体时,由于响应映射问题,我遇到了一些问题。当添加实体时,WCF数据服务返回201状态代码和新添加的实体(作为响应)。是否有可能忽略响应只使用返回的状态代码来检查添加是否成功?
这里的问题可能是修改REST服务,因此一个简单的解决方案是在 postObject 调用某个资源路径时忽略 didFailWithError 的回调。
- (void)objectLoader:(RKObjectLoader *)objectLoader didFailWithError:(NSError *)error {
if ([objectLoader wasSentToResourcePath:@"/rest/api/returns/201" method:RKRequestMethodPOST] && [[objectLoader response] statusCode]==201) {
NSLog(@"Object created");
} else {
UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:@"Communication error"
message:[NSString stringWithFormat:@"Received status code %d: %@", objectLoader.response.statusCode, error.localizedDescription] delegate:nil cancelButtonTitle:@"OK" otherButtonTitles:nil];
[alertView show];
}
[RKObjectMapping mappingForClass: [NSNull class]];