在RestKit 0.2.x中,覆盖RKHTTPRequestOperation中的NSURLConnectionDataDelegate实现,以实现下载进度指示

时间:2015-05-10 18:35:43

标签: nsurlconnection restkit restkit-0.20 nsurlconnectiondelegate

较新的RestKit 0.2.x很棒,但我找不到RKHTTPRequestOperation : AFHTTPRequestOperation : AFURLConnectionOperation<NSURLConnectionDataDelegate>类的任何钩子来扩展它的NSURLConnectionDataDelegate的实现,这是非常必要的我相信实现一个下载进度HUD。

喜欢做的事情是这样的:

RKObjectRequestOperation *operation = 
     [[RKObjectManager sharedManager]
         appropriateObjectRequestOperationWithObject:nil 
         method:RKRequestMethodGET path:_requestPath 
         parameters:_requestParameters];

operation.RKHTTPRequestOperation.onDidReceiveResponse = ^(void)(NSURLConnection *connection, NSURLResponse *response) {
    // store response or at least its estimated length
    _response = response; //OR AT LEAST
    // show progress hud at 0 / length = 0%
   _estimated = response.expectedContentLength;
   [SVProgressHUD showProgress:0.0f];
}

operation.RKHTTPRequestOperation.onDidReceiveData = ^(void)(NSURLConnection *connection, NSData *data) {
     // show updated progress
     [_myData appendData:data];
     [SVProgressHUD showProgress:((float)myData.length/_estimated * 100)];
}

所以,我想知道:

  1. 是否有一个钩子/协议/块/选择器/我不知道RestKitAFNetworking提供什么来实现这一点? (我看到的只有successfailure,这些都太晚了,无法使用。)

  2. 如果没有,最合适,可维护和安全的方法是调整/覆盖/修改NSURLConnectionDataDelegate回调以将其公开给我的客户?

0 个答案:

没有答案