Trying to load images copied into the Application.persistentDataPath

Why does this work fine on an Android device (and the editor) but not iPad?

string path = Path.Combine(Application.persistentDataPath, sTileName+".jpg" );
Debug.Log ( "LoadSavedTileFromDisk:"+path );
if ( File.Exists ( path ) ) {
   ukGeoMenu.GetComponent<ukGeoMenu>().allowMouse = false;
   byte[] data = System.IO.File.ReadAllBytes ( path );
   TileTextures[tile].LoadImage(data);
   TileTextures[tile].name = sTileName;
   ukGeoMenu.GetComponent<ukGeoMenu>().allowMouse = true;
   Debug.Log ( "Success!" );
   returnTileTextures[tile];
 } else {
   Debug.Log ( path + " not found" );
   return (Texture2D)Resources.Load ( "checker_offline_tile_not_found" , typeof(Texture2D));
 }

I’ve copied the images (jpegs) to the Documents folder after the app is installed on iPad (using the flag Application supports iTunes file sharing – YES in Info.plist) , but it doesn’t find them.

(The files were copied into the folder using iFunbox).

The path to document on iPhone is different - I use this and it works ok:

#if UNITY_IPHONE
string path = Environment.GetFolderPath(Environment.SpecialFolder.Personal);

if( !path.EndsWith(“Documents”) )
{
path = Path.Combine(path, “Documents”);
}

string DPath = path + “/”;
#endif

1 Like

Thanks for the reply, were you talking about the global Documents folder on a device? Which is actually quite good to know about, thanks. (There is also a local documents folder for each app).

Anyway, turns out that Android isn’t too fussy about whether or not a filename has lower or uppercase characters in a name whereas iOS only finds a file if the name it’s given is exactly right. My image filenames are all in lower case but I had been generating the names with part of the filename in uppercase.

Note to self: make a list of programming gotchas to reduce hair-pulling and avoid impending baldness…

1 Like