file location on IOS Application.persistentDataPath

string PathForFile(string filename) {
if (Application.platform == RuntimePlatform.IPhonePlayer){
string path = Application.persistentDataPath.Substring(0,Application.persistentDataPath.Length - 5);
path = path.Substring(0,path.LastIndexOf(‘/’));
return Path.Combine(Path.Combine(path, “Documents”), filename);
}
else if(Application.platform == RuntimePlatform.Android){
string path = Application.persistentDataPath;
path = path.Substring(0,path.LastIndexOf(‘/’));
return Path.Combine(path, filename);
}
else{
string path = Application.dataPath;
path = path.Substring(0, path.LastIndexOf(‘/’));
return Path.Combine(path, filename);
}
}

when using this method my saved png and wav files work just fine. They are retrieved and displayed or played with the path returned.
However, once i restart the app on my iPhone or iPad, they don’t work anymore!

I get URL not correct for playing the wav file as an audio clip and get isolatedstrorageexception for png files. Even though the path is correct and was working just fine before restarting the device!

I use the above method along with a file name which has incremented int and save each one’s path as string in a file that also reside in the Application.persistentDataPath, and that file has no problem at all when i retrieve it and it’s a dat file.

Now if the .dat file works just fine, shouldn’t also .wav and .png files get retrieved just fine, since everything else is the same!

I am completely out of things to try. Anyone can help?

HI ,

If you are storing the value of path where you saved the file and then after you restart the app it wont match as the persistent path special folder keeps changing everytime you restart the app.

You will have this issue on IOS , I also have the same issue but i figured this issue today so tomorrow would change my code so that i would just save the relative path to persistantdatapath rather than absolute path and regenerate the path by using combine functionality wherever needed.

Kind Regards
KAshif

Yes, i figured it out already. I now save only the file name into the database, then when i go to retrieve the file i pass only the file name to that method above and now it works :slight_smile:
You think, someone somewhere would mention that, would have saved me days and days of trying to find out what went wrong in my code and i changed my code over and over with no use!