Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>For loading images from the network there are two obvious failure cases:</p> <ol> <li>The downloaded file was not an image at all.</li> <li>The downloaded data only contains part of the image data.</li> </ol> <p>For the first case nil checking the return value of various UIImage methods is probably the best way to handle this error case.</p> <p>The following class methods on <code>UIImage</code> will return nil if the image could not be initialized with the data it was provided: <code>+ (UIImage *)imageWithData:(NSData *)data</code> and <code>+ (UIImage *)imageWithContentsOfFile:(NSString *)path</code>.</p> <p>Code that does the nil check might look like this:</p> <pre><code>UIImage *image = [UIImage imageWithContentsOfFile:pathToImage]; if (image) { // The image was loaded. Display it } else { // The image was not loaded. Redownload or display a placeholder, etc... } </code></pre> <p>For the second failure case it is likely the result of lost connection. For this case the failure is best handled in the NSURLConnection's delegate. When downloading the image if <code>- (void)connection:(NSURLConnection *)connection didFailWithError:(NSError *)error</code> is called then the data for the request should be discarded. </p> <p>Also keep in mind that <code>didFailWithError:</code> will not be called for 4xx or 5xx responses from the server. It is called when the connection is cut off for other reasons. It would generally be a good idea to make sure you only write image data to disk when the server has responded with a 200 OK.</p>
    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.
    1. This table or related slice is empty.
    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