Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>You will have to introduce some more code to include a download status indicator bar. At the moment you download the data with <code>[NSData dataWithConentsOfURL:...]</code>. Instead, you will make a class that uses a <code>NSURLConnection</code> object to download data, accumulate that data in an MSMutableData object, and update your UI accordingly. You should be able to use the <code>ContentLength</code> HTTP header and the <code>- (void)connection:(NSURLConnection *)connection didReceiveData:(NSData *)data;</code> updates to determine the status of the download.</p> <p>Here are some relevant methods:</p> <pre><code>- (void) startDownload { downloadedData = [[NSMutableData alloc] init]; connection = [[NSURLConnection alloc] initWithRequest:request delegate:self startImmediately:YES]; } - (void)connection:(NSURLConnection *)c didReceiveResponse:(NSURLResponse *)response { totalBytes = [response expectedContentLength]; } // assume you have an NSMutableData instance variable named downloadedData - (void)connection:(NSURLConnection *)c didReceiveData:(NSData *)data { [downloadedData appendData: data]; float proportionSoFar = (float)[downloadedData length] / (float)totalBytes; // update UI with proportionSoFar } - (void)connection:(NSURLConnection *)c didFailWithError:(NSError *)error { [connection release]; connection = nil; // handle failure } - (void)connectionDidFinishLoading:(NSURLConnection *)c { [connection release]; connection = nil; // handle data upon success } </code></pre> <p>Personally, I think the simplest way to do this is to create a class that implements the above methods to do generic data downloads and interface with that class.</p> <p>This should be enough to get you what you need.</p>
 

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