objective-c - AFNetworking - 保存下载的文件

标签 objective-c ios download afnetworking

我正在使用 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/

相关文章:

ios - 如何删除现有记录并在核心数据中添加新数据

javascript - 从浏览器到本地连接的 iPhone 的文件传输

python - 使用Boto3从S3下载文件夹

video - 如何提取 YouTube 视频的直接链接?

php - 900 MB http 强制下载很少完成

objective-c - NSArray在访问应用程序时使其崩溃

objective-c - 'instance method not found' 警告的 -Wsomething 标志是什么?

ios - PrepareForSegue 没有传递所有数据?

iphone - iOS 上的蓝牙连接 - 建立连接时应用程序崩溃

ios - 如何阻止 Avaudiosesion 停用?