我正在尝试迁移到 RestKit 0.20-pre2。
目前我设法迁移我的映射(至少编译器不再抱怨),但我在创建请求时遇到问题(之前我使用了不再存在的 RKObjectLoader。
我之前的代码如下:
- (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: parameters: success: failure:
,但是..我需要相同的POST(并且我没有任何要发布的对象...它只是接受登录的POST请求的服务器..)
有什么帮助吗?
谢谢
我和你有同样的问题,我在这里得到了很好的答案:
尝试使用 RestKit 发出 POST 请求并将响应映射到 Core Data https://stackoverflow.com/questions/13962109/trying-to-make-a-post-request-with-restkit-and-map-the-response-to-core-data
基本上,
这就是您所需要的:
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];
自述文件部分的托管对象请求中有一个示例可以帮助您:
https://github.com/RestKit/RestKit https://github.com/RestKit/RestKit
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)