Note that there are some explanatory texts on larger screens.

plurals
  1. PONSURLConnectionDownloadDelegate destinationURL
    primarykey
    data
    text
    <p>I am currently developing an iPad iOS 6 Application which uses async downloads. To receive progress information i used the delegate <code>NSURLConnectionDownloadDelegate</code>. The download and the progress received by </p> <pre><code>– connection:didWriteData:totalBytesWritten:expectedTotalBytes: </code></pre> <p>works just fine.</p> <p>However once the download is finished, i do not know how to extract the data out of the <code>NSURL</code> <code>destinationURL</code> provided by the delegatemethod</p> <pre><code>– connectionDidFinishDownloading:destinationURL: </code></pre> <p>The destinationURL received in String looks like "<code>/private/var/mobile/Applications/7CB3B194-9E79-4F0B-ACFD-7B87AA8C7BAF/tmp/filename.mp4</code>"</p> <p>Then i try to extract the data from the given NSURL:</p> <pre><code>NSData *data = [[NSData alloc] initWithContentsOfURL:destinationURL]; </code></pre> <p>The data however is empty...</p> <pre><code>NSLog(@"data Size: %@", data.length); //prints out 0 </code></pre> <p>Has someone the same issue by using <code>NSURLConnectionDownloadDelegate</code>? Any ideas how to solve?</p> <hr> <p>Edit: I tried to copy the file first, and then use <code>[NSData initWithContentsOFFile]</code> as suggested, but the data size is still 0.</p> <pre><code>- (void) connectionDidFinishDownloading:(NSURLConnection *)connection destinationURL:(NSURL *)destinationURL { [[NSFileManager defaultManager] copyItemAtPath:destinationURL.path toPath:DEST_PATH error:nil]; NSData *data = [[NSData alloc] initWithContentsOfFile:DEST_PATH]; NSLog(@"data Size: %i", data.length); //still returns 0.. } </code></pre> <hr> <p>Edit2: I can extract the <code>NSData</code> when using <code>sendAsynchronousRequest</code> method of <code>NSURLConnection</code>. However like this, i am not able to determine the progress of the download...</p> <pre><code>[NSURLConnection sendAsynchronousRequest:theRequest queue:[[NSOperationQueue alloc] init] completionHandler:^(NSURLResponse *response, NSData *data, NSError *error){ if (data){ NSLog(@"Size of the data: %i Bytes(s)", data.length); //works fine [data writeToFile:DEST_PATH atomically:YES]; //From this point i can use the file at DEST_PATH NSLog(@"Succeeded!"); } else if (error) NSLog(@"%@",error); }]; </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload