AFNetworking - save downloaded file

I am using AFNetworking and can successfully download the file.

At the end of the download, it does not appear in the directory that I installed for it.

I did a few searches and came across a few questions here on SO where I am invited to use:

[_operation setCompletionBlockWithSuccess:^(AFHTTPRequestOperation *operation, id responseObject) { 

But this leads to an error, and as far as I can tell, their documentation is not mentioned.

error:

/ Users / Jeff / Documents / Dropbox-01 / Dropbox / Xcode Projects / Try Outs - JEFF / testDownload / testDownload / JWKDownloadViewController.m: 177: 10: No visible @interface for 'AFURLConnectionOperation' declares selector 'setCompletionBlockWithSuccess: failure:

Is there an updated line that I need to use?

+6
source share
2 answers

Yes make sure u used the correct path in NSOutputStream

Add this:

 [_operation setCompletionBlockWithSuccess:^(AFHTTPRequestOperation *operation, id responseObject) { NSLog(@"Successfully downloaded file"); } failure:^(AFHTTPRequestOperation *operation, NSError *error) { NSLog(@"Error: %@", error); }]; [_operation start]; 
+4
source
  NSURLRequest *request = [NSURLRequest requestWithURL:[NSURL URLWithString:@"..."]]; AFHTTPRequestOperation *operation = [[[AFHTTPRequestOperation alloc] initWithRequest:request] autorelease]; NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES); NSString *path = [[paths objectAtIndex:0] stringByAppendingPathComponent:@"filename"]; operation.outputStream = [NSOutputStream outputStreamToFileAtPath:path append:NO]; [operation setCompletionBlockWithSuccess:^(AFHTTPRequestOperation *operation, id responseObject) { NSLog(@"Successfully downloaded file to %@", path); } failure:^(AFHTTPRequestOperation *operation, NSError *error) { NSLog(@"Error: %@", error); }]; [operation start]; 
+8
source

All Articles