Technical Q&A QA1697

Why doesn't my device load a file that loads fine in the Simulator?

Q:  Why doesn't my device load a file that loads fine in the Simulator?

A: Why doesn't my device load a file that loads fine in the Simulator?

Two things should be kept in mind when accessing files in application bundles using the Simulator versus a device.

Case-sensitivity: iPhone OS uses a case-sensitive file system, unlike the Simulator which uses a case-insensitive file system by default. Make sure the case-sensitivity of resources accessed within code matches the filename case-sensitivity.

For example, if our filename is "YourExampleImage.png":

Location: Methods that require a path should be accessed using the -[pathForResource:ofType:inDirectory:] method of NSBundle. They should not be accessed using a string representation of the filename.

Listing 1  Accessing Default.png from within an application bundle.

UIImage *defaultImage = [UIImage imageWithContentsOfFile:[[NSBundle mainBundle] pathForResource:@"Default" ofType:@"png" inDirectory:nil]];


Document Revision History


DateNotes
2010-06-01

New document that shows how to avoid issues where an app's resources load fine in the Simulator, but not on a device.