【发布时间】:2013-07-21 06:19:33
【问题描述】:
我想从远程 URL 下载视频并将其保存到 iPhone 应用中的文件中。 我知道视频链接有效,因为我已经从 AVPlayer 使用过它,但是我无法下载它。响应始终为 (null)。
以下代码有什么问题?
NSURLRequest *request = [NSURLRequest requestWithURL:[NSURL URLWithString:someURLString]];
AFHTTPRequestOperation *operation = [[AFHTTPRequestOperation alloc] initWithRequest:request];
operation.outputStream = [NSOutputStream outputStreamToFileAtPath:someFilePath append:NO];
[operation setCompletionBlockWithSuccess:^(AFHTTPRequestOperation *operation, id responseObject) {
NSLog(@"Successfully downloaded file to %@", [NSURL fileURLWithPath:someFilePath]);
NSLog(@"THE RESPONSE: %@", responseObject);
} failure:^(AFHTTPRequestOperation *operation, NSError *error) {
NSLog(@"Error: %@", error);
}];
[operation start];
更新
我注释掉了 operation.outputStream 这一行,这次我得到了回应。这是否意味着文件路径有问题?
【问题讨论】:
-
文件下载了吗?
-
不,操作总是“成功”,但没有下载任何东西@H2CO3
-
您是否尝试将其下载到应用程序包中?
-
不,到文档目录@H2CO3 中的一个文件夹
-
查看更新后的问题,@H2CO3
标签: iphone ios objective-c cocoa-touch afnetworking