解决 NSURLErrorCannotOpenFile 错误
我编写了一些代码,使用 NSURLRequest 和 NSURLDownload 将 URL 下载到磁盘。下载开始正常(至少,它发送 downloadDidBegin:(NSURLDownload *)download
),但随后它发送
-(void)download:(NSURLDownload *)download didFailWithError:(NSError *)error
我的函数实现如下:
{
[download release];
NSLog(@"Download failed! Error - %@ %@",
[error localizedDescription],
[[error userInfo] objectForKey:NSURLErrorFailingURLStringErrorKey]);
}
记录的错误是
2011-07-17 01: 48:43.194 URLDownloader[28031:903] 下载失败!错误 - 操作无法完成。 (NSURLErrorDomain 错误 -3001。) [NSURLRequest 中的 URL]
据我所知,这是 NSURLErrorCannotOpenFile 错误。除了“当 NSURLDownload 无法打开磁盘上下载的文件时返回”之外,我找不到任何解释为什么会发生此错误。从文档中。那么,为什么会发生这种情况呢?
可能有帮助的事实(?):NSURLErrorCannotOpenFile 被枚举为 kCFURLErrorCannotOpenFile。我也不知道这意味着什么......
I wrote some code to download a URL to my disk, using an NSURLRequest and an NSURLDownload. The download starts fine (at least, it sends downloadDidBegin:(NSURLDownload *)download
), but then it sends
-(void)download:(NSURLDownload *)download didFailWithError:(NSError *)error
My implementation of the function is as follows:
{
[download release];
NSLog(@"Download failed! Error - %@ %@",
[error localizedDescription],
[[error userInfo] objectForKey:NSURLErrorFailingURLStringErrorKey]);
}
The logged error is
2011-07-17 01:48:43.194 URLDownloader[28031:903] Download failed! Error - The operation couldn’t be completed. (NSURLErrorDomain error -3001.) [the URL in the NSURLRequest]
From what I can tell, this is the NSURLErrorCannotOpenFile error. I cannot find any explanation of why this error occurs, other then "Returned when NSURLDownload was unable to open the downloaded file on disk." from the documentation. So, why is this happening?
Fact that might be helpful(?): NSURLErrorCannotOpenFile is enumerated as kCFURLErrorCannotOpenFile. I have no idea what this means either....
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
好吧,所以我只是犯傻了。我使用 NSURL 的 AbsoluteString 方法而不是 path 方法创建了一个路径。这对我来说只是糟糕的编码......
Alright, so I was just being foolish. I had created a path using NSURL's absoluteString method instead of the path method. This was just bad coding on my part...