解决 NSURLErrorCannotOpenFile 错误

发布于 2024-11-24 05:01:52 字数 817 浏览 1 评论 0原文

我编写了一些代码,使用 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

飘落散花 2024-12-01 05:01:52

好吧,所以我只是犯傻了。我使用 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...

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文