我想从一个远程网址下载一个视频,并把它保存到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行,这一次我得到了响应。这是否意味着文件路径有问题?
发布于 2013-07-21 08:42:54
这就是问题所在。
我正在使用视频的url,作为文件路径的一部分。
为什么这样做不对?它有反斜杠,所以我猜想iOS会感到困惑。
经验教训:确保添加到目录中以创建文件的字符串没有反斜杠.
我希望这能帮助其他犯了这个愚蠢错误的人。:P
https://stackoverflow.com/questions/17769651
复制相似问题