现在,我正在对我的代码做一个巨大的重新构思,我想统一我使用雷斯基特的方式。我已经将RPC的通话方式与我的API服务器和REST的通话方式区分开来。
使用物体绘图和 RPC 调用RKClient 调用RCC。 此外,我使用街区而不是代表,这是件好事,但我对它如何运作有些怀疑。
这是我之前的代码, 它很好地张贴了对象, 并用代表手动绘制地图, 之后是使用不发送参数的区块的新代码。
//This was the old way...
- (void) upload: (KFMedia *) pic {
RKParams* imageParams = [RKParams params];
NSData* imageData = UIImageJPEGRepresentation(pic.image, 0.7f);
[imageParams setData:imageData MIMEType:@"image/jpg" forParam:@"FileUpload"];
[[RKClient sharedClient] post:@"/api/upload/" params:imageParams delegate:self];
}
//This is the new way I m trying...
- (void) upload: (KFMedia *) pic onLoad:(RKObjectLoaderDidLoadObjectBlock) loadBlock onError:(RKRequestDidFailLoadWithErrorBlock)failBlock{
RKParams* imageParams = [RKParams params];
NSData* imageData = UIImageJPEGRepresentation(pic.image, 0.7f);
[imageParams setData:imageData MIMEType:@"image/jpg" forParam:@"FileUpload"];
[[RKObjectManager sharedManager] loadObjectsAtResourcePath:@"/api/upload/" usingBlock:^(RKObjectLoader *loader) {
//Trying to set params here, but it seems that I m not sending anything :(
loader.params = imageParams;
loader.objectMapping = [[RKObjectManager sharedManager].mappingProvider objectMappingForClass:[KFMedia class]];
loader.delegate = self;
loader.onDidLoadObject = loadBlock;
loader.onDidFailWithError = failBlock;
loader.onDidFailLoadWithError = failBlock;
loader.onDidLoadResponse = ^(RKResponse *response) {
[self fireErrorBlock:failBlock onErrorInResponse:response];
};
}];
}
我发送的请求是空的,这意味着参数没有被正确发送或设置。 对于如何使参数发挥作用有什么想法?