11

I'm trying to get a list of assests urls to download. I'm using NSURLConnection in order to get a JSON file that have this list of urls. in

- (void)connection:(NSURLConnection *)connection didWriteData:(long long)bytesWritten totalBytesWritten:(long long)totalBytesWritten 

I'm getting 122239 as total bytes written. when

- (void)connectionDidFinishDownloading:(NSURLConnection *)connection destinationURL:(NSURL *)destinationURL

is called I'm trying to read the url data in order to extract the JSON file:

NSData *data = [NSData dataWithContentsOfURL:destinationURL options:NSDataReadingUncached error:&error];

data is always giving me a nil value also there is 122239 byte written in this file and the error print description is showing "No such file or directory"

Error Domain=NSCocoaErrorDomain Code=260 "The operation couldn\u2019t be completed. (Cocoa error 260.)" UserInfo=0x4a1b90 {NSFilePath=/private/var/mobile/Applications/CD8E4838-D78D-41DE-8896-360B7FC02A1D/tmp/c1749157e1d4317f6158a8490e138e7e, NSUnderlyingError=0x4c5ae0 "The operation couldn\u2019t be completed. No such file or directory"}

Any suggestions?

0x8badf00d
  • 6,391
  • 3
  • 35
  • 68
mukaissi
  • 2,441
  • 1
  • 21
  • 12
  • I've got the same problem and did some googleling. This seems to be a bug. Hopefully an iOS update will fix this. – Klaas Oct 27 '11 at 18:54
  • Did you file a radar at http://bugreport.apple.com ? If you think this is a bug, and you have a small code sample to demonstrate, you increase the chances of this being fixed dramatically, in my experience. – Philippe Jan 02 '12 at 01:00
  • 1
    Did you file a bugreport for this? I just ran into the exact same problem you had. Everything works perfectly, expect the file does't exist like in the destinationURL. – DBD Aug 09 '12 at 15:31
  • I submitted this as a bug to Apple. Apple confirmed this is a bug and marked confirmed it has been reported by at least one other person by marking it as a duplicate. – DBD Aug 15 '12 at 18:03
  • I wasted my full day on this. – Asad Khan Nov 24 '12 at 13:37

4 Answers4

10

NSURLConnectionDownloadDelegate only works for Newstand apps so far. Please file a bug.

0x8badf00d
  • 6,391
  • 3
  • 35
  • 68
Julien
  • 3,427
  • 20
  • 22
3

You could try to use NSURLConnectionDataDelegate instead. It won't show up in the docs, but it's actually there (use Open Quickly to find it Cmd+Shift+O).

There you could use following methods

  1. - (void)connection:(NSURLConnection *)connection didReceiveData:(NSData *)data
  2. - (void)connectionDidFinishLoading:(NSURLConnection *)connection
0

iIf NSURLConnectionDownloadDelegate methods present in you class, NSURLConnectionDataDelegate will not be called. Watch out! – jAckOdE Thanks to a comment in Erik Aigner's answer below.

Basically... The NSURLConnectionDownloadDelegate overrides NSURLConnectionDataDelegate. Beware!!! :)

Uxonith
  • 1,602
  • 1
  • 13
  • 16
0
– (void)connection:(NSURLConnection *)connection didReceiveData:(NSData*)data

Above method is used to receive the data which we get using post method.

– (void)connection:(NSURLConnection *)connection didFailWithError:(NSError *)error

This method , you can use to receive the error report in case of connection is not made to server.

– (void)connectionDidFinishLoading:(NSURLConnection *)connection

The above method is used to process the data after connection has made successfully.

Rajesh
  • 10,318
  • 16
  • 44
  • 64
vishal
  • 11
  • 1