简体   繁体   English

Restkit 0.20中的didReceiveResponse委托方法

[英]didReceiveResponse delegate method in Restkit 0.20

I am using Restkit 0.20 for my project. 我正在为我的项目使用Restkit 0.20。 I make a request like this. 我这样要求。

NSData *postData  = [params dataUsingEncoding:NSUTF8StringEncoding];
    NSURL *url = [NSURL URLWithString:baseUrl];
    NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:[NSURL URLWithString:path relativeToURL:url]];
    [request setHTTPMethod:@"POST"];
    [request setValue:@"application/json" forHTTPHeaderField:@"Content-Type"];
    [request setHTTPBody:postData];
    RKObjectManager *manager = [[RestKit sharedDataManager] objectManager];
    RKManagedObjectRequestOperation *operation = [manager managedObjectRequestOperationWithRequest:request managedObjectContext:manager.managedObjectStore.persistentStoreManagedObjectContext success:^(RKObjectRequestOperation *operation1, RKMappingResult *mappingResult) {
             block ([mappingResult array]);

        } failure:^(RKObjectRequestOperation *operation1, NSError *error) {
            RKLogDebug(@"Failure %@",error.debugDescription);
            block (error);
        }];

After competing mapping operation, i am returning an array using block. 在竞争映射操作之后,我正在使用block返回一个数组。 I need to get a response in a delegate to use for some operation. 我需要在委托中获得响应才能用于某些操作。 Is there any method similar to didReceiveResponse in Restkit0.10 and also i am aware of this thread https://groups.google.com/forum/#!topic/restkit/TrWH5GR-gFU in which blake mentioned that we have full control over the headers via the NSURLRequest object. 是否有任何与Restkit0.10中的didReceiveResponse类似的方法,并且我也知道此线程https://groups.google.com/forum/#!topic/restkit/TrWH5GR-gFU ,其中blake提到我们可以完全控制标头通过NSURLRequest对象。 But how can i make use of NSURLRequest when i am using RKManagedObjectRequestOperation. 但是当我使用RKManagedObjectRequestOperation时如何使用NSURLRequest。 can anyone post some example. 任何人都可以发表一些例子。

Thanks 谢谢

if you just need response.statuscode you can get it. 如果您只需要response.statuscode,则可以获取它。 in restkit success block we have two parameters (RKObjectRequestOperation *operation, RKMappingResult *result) 在restkit成功块中,我们有两个参数(RKObjectRequestOperation * operation,RKMappingResult * result)

to get response you can use this. 要获得回应,您可以使用此功能。

operation.HTTPRequestOperation.response.statusCode

You already have a request : NSMutableURLRequest (which is the mutable subclass of NSURLRequest ), so any required headers can be set there. 您已经有一个请求: NSMutableURLRequest (这是NSURLRequest的可变子类),因此可以在此处设置任何必需的标头。

When the success callback is called it includes the RKObjectRequestOperation , you can request the HTTPRequestOperation (an instance of RKHTTPRequestOperation ), from which you can request response (an instance of NSHTTPURLResponse ). 调用success回调时,它包含RKObjectRequestOperation ,您可以请求HTTPRequestOperationRKHTTPRequestOperation的实例),从中可以请求responseNSHTTPURLResponse的实例)。


Based on your updated description you would need to subclass RKManagedObjectRequestOperation and override performMappingOnResponse: in order to insert your additional processing before calling super . 根据更新的描述,您将需要子类RKManagedObjectRequestOperation并重写performMappingOnResponse:以便在调用super之前插入其他处理。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM