Hi, i’m trying to create a file in iOS, but i don’t find a valid path to save it.
I already test on Editor and Android and both work, but for iOS no, dunno why.
IEnumerator Download()
{
string myPath;
if(Application.platform == RuntimePlatform.Android)
myPath = “/storage/emulated/0/Download/30.wtc”; //ANDROID (work)
else if(Application.platform == RuntimePlatform.IPhonePlayer)
{
myPath = Application.dataPath + “30.wtc”; //iOS
myPath = myPath.Replace (“/game.app/Data”, “/tmp/”); //this path dont work
File.Create ( myPath ); //tryied with and without
}
else
myPath = Application.streamingAssetsPath + “/30.wtc”; //Editor (work)
I tryied also with “/Documents/” repalced with “/tmp/” in the script, and the error in XCode is the same:
path dont found
If i try to save on the data path XCode give this error:
UnauthorizedAccessException: Access to the path “/var/containers/Bundle/Application/A5ACC159-D58B-496E-BA3V-668546FC378C/game.app/Data/Resources/30.wtc” is denied.
I tryed also:
myPath = Application.absoluteURL + “/Documents/30.wtc”;
myPath = Application.dataPath + “/Resources/30.wtc”;
myPath = Application.persistentDataPath + “/30.wtc”;
but are all wrong methods.
Can anyone tell me where is my issue? I have to use File.Create or not? I was wrong with the path?
Thanks a lot
You should be able to use Application.persistentDataPath for all platforms. File.WriteAllBytes will create the file for you as well. (shouldn’t have to use File.Create)
Also as a friendly note. Don’t use IF checks for platform checks. Use the platform specific tags, so it only includes the code that is needed for the platform it’s on.
Ok, i remove the File.Create, but i tried without and dont work as well.
I don’t know why, but on Andorid and iOS"PersistentDataPath" don’t work, so i have use that link in Andorid for let it work,
maybe is the format of the file i’m using?
Now i’ll try again to compile in iOS with persistent data path, but i alredy now that doesn’t work.
There is my new code:
Are you using something like log viewer to view errors/debugs?
I would see what errors are being shown, if any, on the device. You can also use File.Exist to check for the file.
Honestly, I can’t tell you why persistentDataPath isn’t working for you on all platforms. We use it in several of our apps and it works perfectly fine. I’m not aware of any special settings needed on iOS. Android I believe does require a manifest permission if I recall, but usually that’s not a big deal to include that. I’m not sure why you are having issues.
I caution against using a path directly as it may not exist. The purpose of persistentDataPath is to point to a path that will exist and it is setup for the devices.