iOS-下载视频 [英] iOS - Download Video
本文介绍了iOS-下载视频的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想从远程URL下载视频并将其保存到iPhone应用程序中的文件中。
我知道视频链接有效,因为我从AVPlayer,但是,我无法下载它。响应始终为(空)。
I'd like to download a video from a remote URL and save it to a file in an iPhone app. I know the video link works, since I have used it from AVPlayer, however, I am unable to download it. The response is always (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];
更新
Update
我注释掉了operation.outputStream行,这一次我得到了响应。
推荐答案
这是问题所在。
我正在使用视频的url,并将其作为文件路径的一部分。
I was using the url of the video, and as part of the file path.
为什么这是错误的?它带有反斜杠,因此我认为iOS会感到困惑。
Why is this wrong? It has backslashes, so I assume iOS was getting confused.
经验教训:请确保添加到目录中以创建文件的字符串不会我要反斜杠。
我希望这对犯这个愚蠢错误的人有所帮助。 :P
I hope this helps anyone else who makes this silly mistake. :P
这篇关于iOS-下载视频的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文