I would like to save and read the xml file. But the path is always incorrect. Who can help me? If I direct access to the path, then the $: / xxxx-xxx-xxx/data/filename.xml The real path is: $: / xxxx-xxx-xxx/appname.app/data/filename.xml I am programming problem, or bug? Thank you. :wink:
// Application.dataPath returns something like "/var/mobile/Applications/30B51836-D2DD-43AA-BCB4-9D4DADFED6A2/Data" Why not:like "/var/mobile/Applications/30B51836-D2DD-43AA-BCB4-9D4DADFED6A2/AppName.app/Data"
Try something like this: Code (csharp): string root = Application.dataPath.Substring(0, Application.dataPath.Length - 4) + "Documents"; if (System.IO.Directory.Exists(root)) { return root; // for phone } else { return ""; // for development on PC (not phone) }
Does anyone know a way to get the name of the app (in code), so the appropriate number of characters can be removed from the Application.dataPath string?
It's probably much safer to use '/../' than Substring. For Documents I currently use: Application.dataPath + "/../../Documents/"; It works like a charm for me.
If you have iPhone Advanced using ObjC is much faster and especially future proof cause it does not depend on apple not messing with the structure. The following function for example returns the path to the cache dir which is what you commonly want to use (not documents - cause cache is not backed up in itunes. you would use this for downloadable levels etc): put this into an .mm file in your xcode project Code (csharp): extern "C" const char * getCacheDirectory() { NSString* cacheDir = [NSSearchPathForDirectoriesInDomains(NSCachesDirectory, NSUserDomainMask, YES) lastObject]; return cocoaToMonoString(cacheDir); } and in unity add a C# class to the plugins folder and add Code (csharp): [DllImport ("__Internal")] public static extern string getCacheDirectory(); dang and you can happily ask your os about the path to cache directory To get the documents directory, replace NSCachesDirectory with NSDocumentDirectory