1

The newer RestKit 0.2.x is great but I cannot find any hook out of the RKHTTPRequestOperation : AFHTTPRequestOperation : AFURLConnectionOperation<NSURLConnectionDataDelegate> class to extend it's implementation of NSURLConnectionDataDelegate, which is quite necessary I believe to implement a download progress HUD.

What I would like to do is something like this:

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

So, I'd like to know:

  1. Is there a hook/protocol/block/selector/whatever I am not aware of that RestKit or AFNetworking provides to make this possible? (All I see is success and failure, which are both too late to be of use).

  2. If not, what is the most appropriate and maintainable and safe way to swizzle/override/modify the NSURLConnectionDataDelegate callbacks to expose them to my client?

tacos_tacos_tacos
  • 10,277
  • 11
  • 73
  • 126

1 Answers1

0

Similar to your proposition you should be able to use:

[operation.RKHTTPRequestOperation setDownloadProgressBlock:...]
Wain
  • 118,658
  • 15
  • 128
  • 151