Restkit:迁移到0.20 [英] Restkit: migrating to 0.20
问题描述
我正在尝试迁移到RestKit 0.20-pre2.
I am trying to migrate to RestKit 0.20-pre2.
目前,我设法迁移了映射(至少编译器不再抱怨了),但是我在创建请求时遇到了问题(以前我使用的是RKObjectLoader,现在不再存在了.)
Currently I managed to migrate my mapping (at least the compiler does not complain anymore), but I have problems in creating requests (previously I used the RKObjectLoader which does not exist anymore.
我之前的代码如下:
- (RKObjectLoader*)objectLoaderWithResourcePath: (NSString*)resourcePath
method: (RKRequestMethod)httpMethod
parameters: (NSDictionary*)parameters
mappableClass: (Class)objectClass
{
RKObjectMapping *mapping = [self.objectManager.mappingProvider objectMappingForClass:objectClass];
NSString *path = resourcePath;
if (httpMethod == RKRequestMethodGET) {
path = [resourcePath stringByAppendingQueryParameters:parameters];
}
RKObjectLoader *request = [self.objectManager loaderWithResourcePath:path];
request.method = httpMethod;
request.delegate = self;
request.objectMapping = mapping;
if (httpMethod != RKRequestMethodGET) {
request.params = parameters;
}
return request;
}
我使用上述方法创建了一个通用请求,然后以同步或异步方式发送该请求.现在...我看到了新方法 getObjectsAtPath:参数:成功:失败:
,但是..我需要相同的POST(并且我没有要发布的任何对象...它仅仅是接受登录请求的POST请求的服务器.)
I used the above method to create a generic request, and then send it either synchronously or asynchronously.
Now... I saw the new method getObjectsAtPath: parameters: success: failure:
, but.. I need the same for the POST (and I don't have any object to post... it is simply the server which accept a POST request for the login..)
有帮助吗?
谢谢
推荐答案
我遇到了与您相同的问题,在这里我得到了一个很好的答案:
I had the same problem as you and i received a great answer here:
尝试使用 RestKit 发出 POST 请求并将响应映射到核心数据
基本上
这是您需要的:
NSDictionary *dictionary = @{ @"firstParam": @(12345), @"secondParam": @"whatever"};
NSMutableURLRequest *request = [objectManager requestWithObject:nil method:RKRequestMethodPOST path:@"/whatever" parameters:parameters];
RKObjectRequestOperation *operation = [objectManager objectRequestOperationWithRequest:request ^(RKObjectRequestOperation *operation, RKMappingResult *result) {
NSLog(@"Loading mapping result: %@", result);
} failure:nil];
自述文件"部分的受管对象请求"中有一个示例可以帮助您:
There is an example here in README section Managed Object Request that will help you:
https://github.com/RestKit/RestKit
这篇关于Restkit:迁移到0.20的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!