Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Unable to get destinationURL data in connectionDidFinishDownloading for ios5

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?

like image 765
mukaissi Avatar asked Jul 18 '11 15:07

mukaissi


2 Answers

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

like image 168
Julien Avatar answered Oct 20 '22 00:10

Julien


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
like image 34
Era Avatar answered Oct 19 '22 22:10

Era