I am using AFNetworking and can successfully download a file.
At the end of the download, it does not appear in the directory that I set it to be though.
I did some searching and came across a few questions here on SO where it is suggested I use:
[_operation setCompletionBlockWithSuccess:^(AFHTTPRequestOperation *operation, id responseObject) {
But that comes up with an error and it is as far as I can tell not mentioned in their documentation.
the error is :
/Users/Jeff/Documents/Dropbox-01/Dropbox/Xcode Projects/Try Outs - JEFF/testDownload/testDownload/JWKDownloadViewController.m:177:10: No visible @interface for 'AFURLConnectionOperation' declares the selector 'setCompletionBlockWithSuccess:failure:'
Is there an updated line I need to use???
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];
Yes make sure that u have used correct path into NSOutputStream
Add this:
[_operation setCompletionBlockWithSuccess:^(AFHTTPRequestOperation *operation, id responseObject) {
NSLog(@"Successfully downloaded file");
} failure:^(AFHTTPRequestOperation *operation, NSError *error) {
NSLog(@"Error: %@", error);
}];
[_operation start];
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With