Man, stumped on this one. Trying to download a file with AFNetworking and the best I can do is capture the progress bytes in the downloadProgressBlock. I've tried many different forks of AFNetworking and now I'm back to the latest build. Looks like at one time the AFHTTPRequestOperation was modified to also include NSURLResponse but that's gone in the latest release. And, per the code below, the "success" block is never called. I get a log of the downloaded bytes and then ^complete is called. success and error are never called.
Any guidance on this would be awesome. I can't figure out where the data is returned and how to get it to use NSFileManager on it? I need to download files, not write streams for images, etc.
Edit: I've also tried to capture the data by overriding - (void)connection:didReceiveData as suggested in the documentation but nothing doing there.
// url is http://mydomain.com/somezip.zip
NSURLRequest *request = [NSURLRequest requestWithURL:[NSURL URLWithString:[NSString stringWithFormat:@"%@", url]]];
AFHTTPRequestOperation *operation = [AFHTTPRequestOperation HTTPRequestOperationWithRequest:request success:^(id object) {
NSLog(@"hey, some success!");
} failure:^(NSHTTPURLResponse *response, NSError *error) {
NSLog(@"%@", error);
}];
[operation setDownloadProgressBlock:^(NSInteger bytesRead, NSInteger totalBytesRead, NSInteger totalBytesExpectedToRead) {
// callback is sent in and works great. Just outputting to the console at the moment
SEL callme = NSSelectorFromString(callback);
[sender performSelectorOnMainThread:callme withObject:[NSNumber numberWithInt:bytesRead] waitUntilDone:NO];
}];
[operation setCompletionBlock:^{
NSLog(@"operation complete");
}];
NSOperationQueue *queue = [[[NSOperationQueue alloc] init] autorelease];
[queue addOperation:operation];