我正在使用 AFNetworking 并且可以成功下载文件。
下载结束时,它并没有出现在我设置的目录中。
我进行了一些搜索,并在建议我使用的 SO 上遇到了一些问题:
[_operation setCompletionBlockWithSuccess:^(AFHTTPRequestOperation *operation, id responseObject) {
但这会带来错误,据我所知,他们的文档中并未提及。
错误是:
/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:'
是否有我需要使用的更新线路???
最佳答案
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];
关于objective-c - AFNetworking - 保存下载的文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14152397/