NSURLConnectionDownloadDelegate file issue
Asked Answered
H

4

11

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.

Heifetz answered 13/10, 2011 at 12:55 Comment(4)
I submitted this as a bug to Apple. Apple confirmed this is a bug, and marked it as a duplicate, so it's been reported by at least 1 other person.Pretermit
This bug is still happening, on iOS 6 - did you find any solution? I have sample code demonstrating the issue.Paco
Same problem here, iOS 6.0.1Albi
anyone found solution to this??Syrup
P
4

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.

Prosaic answered 15/12, 2012 at 14:42 Comment(0)
G
1

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.

Griqua answered 13/10, 2011 at 13:21 Comment(5)
Thanks. I am indeed trying to move it within the method. The file name is catalog.sqlite which does not seem too cryptic but I will try it with something plainer and report back.Heifetz
Nope. Does not work with a pdf or jpg file. I can print out [destinationURL path] and see the file path and filename. But then a call to [[NSFileManager defaultManager] fileExistsAtPath:[destinationURL path]] returns false.Heifetz
is NSURLConnectionDownloadDelegate the only NSURLConnection related protocol your class implements?..Griqua
that plus the NSURLConnectionDelegate protocol in which I only use didReceiveResponseHeifetz
try commenting out that one.. NSURLConnection now behaves differently for the type of delegate you pass (which i consider a bad design anyway)Griqua
M
1

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.

Mali answered 4/11, 2011 at 18:0 Comment(1)
Duncan, I can't find an NSURLConnectionDataDelegate in my iOS5 documentation. There is a new NSURLConnectionDownloadDelegate which is the subject of the discussion above. If you use that delegate as described in the documentation, the file that is supposed to be downloaded does not exist in the temporary location in which it is supposed to be found. However, if you use the now-deprecated methods as described in the class reference for NSURLConnection, you will find that they still work OK in spite of the warning that they are available only through iOS 4.3Heifetz
K
1

Even now NSURLConnectionDownloadDelegate doens't work.

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

Kearns answered 1/12, 2011 at 8:12 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.