gpt4 book ai didi

macos - Restkit:迁移到 0.20

转载 作者:行者123 更新时间:2023-12-01 02:30:02 26 4
gpt4 key购买 nike

我正在尝试迁移到 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/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com