macos - Restkit:迁移到 0.20

标签 macos restkit restkit-0.20

我正在尝试迁移到 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请求的服务器......)

有什么帮助吗?

谢谢

最佳答案

我和你有同样的问题,我在这里得到了很好的答案:

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];

README 部分 Managed Object Request 中有一个示例,可以帮助您:

https://github.com/RestKit/RestKit

关于macos - Restkit:迁移到 0.20,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13722830/

相关文章:

ios - 在 POST JSON RestKit 中检索到 null

ios - RestKit 和压缩的 json

ios - RESTKIT 将 JSON 与 text/html 内容类型映射

macos - 如何让虚拟主机在 OS X Lion 中工作?

macos - 这种 x86 调用约定的原因是什么?

macos - Swift - 使用定时器/系统时钟/后台线程每小时在我的应用程序中做一些事情

ios - 使用 RestKit 发布多个对象(作为 JSON 数组)

iphone - 获取响应映射对象的Json字符串 restkit v0.2.20

java - MacOS 多线程问题?

ios - 当响应包含在数组中时,RestKit POSTed 托管对象变得重复