NSURLConnectionDownloadDelegate 文件问题

发布于 2024-12-09 19:06:20 字数 597 浏览 2 评论 0原文

现在 5.0 已经发布,我们可以在不违反 Apple 保密协议的情况下讨论它,我对新版本的 NSURLConnection 有一个问题。它有一个新的委托 NSURLConnectionDownloadDelegate ,它有两个关键方法。

  1. connection:didWriteData:totalBytesWritten:expectedTotalBytes: 在文件下载过程中重复调用

  2. connectionDidFinishDownloading:destinationURL: 被调用下载完成后一次。

下载的文件应该位于destinationURL(至少在该方法的生命周期内 - 目的是您获取它并将其移动到永久的地方)。问题是:它不存在。该目录是空的。我已将此作为错误报告给 Apple,他们告诉我这是他们已经意识到的问题的重复。

如果有人对此有解决方法,或者发现他们可以成功使用此委托,请告诉我。

2011 年 10 月 17 日更新:我已经放弃了这一点,回到了旧的委托,它在 5.0 中仍然可以正常工作,尽管文档说委托方法只能在 4.3 版本中使用。

Now that 5.0 is launched and we can discuss it without breaching Apple's NDA, I have an issue with the new version of NSURLConnection. This has a new delegate, NSURLConnectionDownloadDelegate with two key methods.

  1. connection:didWriteData:totalBytesWritten:expectedTotalBytes: is invoked repeatedly while the file download is progressing

  2. connectionDidFinishDownloading:destinationURL: is called once when the download is complete.

The downloaded file should then be at destinationURL (at least for the life of this method - the intent is that you get it and move it somewhere permanent). The issue is : it's not there. That directory is empty. I have reported this as a bug to Apple and they tell me it is a duplicate of an issue that they are already aware of.

If anyone has a workaround for this, or finds they can use this delegate successfully, please let me know.

UPDATE 10/17/2011 : I've given up on this and gone back to the old delegate which still works fine in 5.0 even though the documentation says the delegate methods are only available thru 4.3.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

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

发布评论

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

评论(4

离鸿 2024-12-16 19:06:20

显然仅适用于报亭应用程序。这家伙可能找到了解决方法:

http://adamernst.com/post/ 18948400652/a-replacement-for-nsurlconnectiondownloaddelegate

或者,只需使用 NSURLConnection。但请注意,如果您实现 NSURLDownloadDelegate 方法,它们似乎会覆盖标准 NSURLConnection 委托方法。如果您想要使用 NSURLConnectionDownloadDelegate 的 didWriteData: 方法(例如更新 UIProgressView),则可以通过从 http 响应中获取总文件大小并使用 NSURLConnection 的 didReceiveData: 方法来实现相同的目的。

Apparently only for use with Newsstand apps. This guy might have found a work around:

http://adamernst.com/post/18948400652/a-replacement-for-nsurlconnectiondownloaddelegate

Alternatively, just use NSURLConnection. But heads up if you implement the NSURLDownloadDelegate methods, they appear to override the standard NSURLConnection delegate methods. If it's the handy didWriteData: method of NSURLConnectionDownloadDelegate that you want, e.g. to update a UIProgressView, you can achieve the same by grabbing the total file size from the http response, and by using the didReceiveData: method of NSURLConnection.

心的憧憬 2024-12-16 19:06:20

文档告诉我们,只有在调用委托方法时才能保证该文件存在,因此您需要在调用委托方法时将其复制到其他地方。

谷歌告诉我,当服务器发送神秘的文件名和/或 mime 类型时,人们会遇到问题。

Documentation tells the file is only guaranteed to exist while the delegate method is called so you will need to copy it somewhere else the moment the delegate method is called.

Google tells me people are having problems when the Server sends a cryptic filename and/or mime-type.

诗酒趁年少 2024-12-16 19:06:20

各位,

我最近发现了这个新的 NSURLConnectionDataDelegate 协议。然而,iOS 5 文档并不完整。

新的 NSURLConnectionDataDelegate 协议在文档中,但使用它的新版本 NSURLConnection 却没有。该文档仍然告诉我们使用现已弃用的 NSURLConnectionDelegate 协议方法。

据我所知,NSURLConnection 现在会将数据从远程 URL 直接下载到本地磁盘上的文件,就像 Mac OS 中的 NSURLDownload 类一样。我如何弄清楚这是如何工作的?

NSURLConnection 的标头暗示连接对象根据委托符合的 NSURLConnectionDelegate 协议版本推断出您想要的内容。这看起来真的很搞怪。我以前从未听说过使用委托的协议一致性作为控制类行为的方法。

Folks,

I've recently discovered this new NSURLConnectionDataDelegate protocol. However, the iOS 5 documentation is incomplete.

The New NSURLConnectionDataDelegate protocol is in the documentation, but the new version of NSURLConnection that uses it is not. That documentation still tells us to use the now deprecated NSURLConnectionDelegate protocol methods.

I gather that NSURLConnection will now download data from a remote URL directly to a file on the local disk, much like the NSURLDownload class in Mac OS. How do I figure out how this works?

The header for NSURLConnection hints that the connection object deduces what you want based on which version of the NSURLConnectionDelegate protocol the delegate conforms to. That seems really screwy. I've never heard of using the protocol conformity of a delegate as a way of controlling the behavior of a class before.

童话里做英雄 2024-12-16 19:06:20

即使现在 NSURLConnectionDownloadDelegate 也不起作用。

这是一个很好的替代品:
http://github.com/jbrennan/JBContainedURLConnection

Even now NSURLConnectionDownloadDelegate doens't work.

Here is a good replacement:
http://github.com/jbrennan/JBContainedURLConnection

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