-
1. Re: iOS 8 - FileStream throwing error 2038 on open for write?
Jeffrey Adams Jul 22, 2014 9:07 AM (in response to Eljo.huckleberry)Does it make a difference if you replace:
var storagePath:File = new File(File.applicationDirectory.nativePath + "/\.\./Documents");
with:
var storagePath:File = File.documentsDirectory;
??
You should really be using File.documentsDirectory and not that assumption about walking up from a relative path from File.applicationDirectory anyway.
-
2. Re: iOS 8 - FileStream throwing error 2038 on open for write?
Eljo.huckleberry Jul 22, 2014 9:54 AM (in response to Jeffrey Adams)Thanks for your quick reply!
I agree about not traversing up the directory tree, but a blog post from an Adobe employee I read a long time ago put me on that track: Saumitra Bhave: AIR iOS- Solving [Apps must follow the iOS Data Storage Guidelines]
Anyway, I ran some tests including your suggested solution and it returns an interesting result:
#1 File.documentsDirectory (iOS 8)
Full path = /var/mobile/Containers/Data/Application/<UUID>/Documents
Result: works as expected, no errors thrown!
#2 new File(File.applicationDirectory.nativePath + "/\.\./Documents") (iOS 8)
Full path = /private/var/mobile/Containers/Bundle/Application/<UUID>/Documents
Result: error, no write permission! (as I would expect with 'private' being there)
#3 File.documentsDirectory (iOS 7)
Full path = /var/mobile/Applications/<UUID>/Documents
Result: works as expected!
#4 new File(File.applicationDirectory.nativePath + "/\.\./Documents") (iOS 7)
Full path = /var/mobile/Applications/<UUID>/Documents
Result: works as expected! (notice it's exactly the same as #3)
So, while the storage directory is easily adjustable and #1 should fit the bill nicely, I'm thinking of how to preserve user data when people begin updating from iOS 7 to iOS 8 as it will be kind of hard for me to locate my earlier data on iOS8 unless part of the update process is to also relocate all application data? I mean, even if I had used File.documentsDirectory before, this would still be a potential problem? In any case, it's obvious the iOS8 file system is different.
How is this going to work?
-
3. Re: iOS 8 - FileStream throwing error 2038 on open for write?
Jeffrey Adams Jul 22, 2014 11:01 AM (in response to Eljo.huckleberry)Well I think this clearly shows that #1 is the way to go, yes it looks like Apple is moving the location of the apps in iOS 8 on the filesystem, but obviously the update on a device to the new OS version would have to move all apps, otherwise every single app would break.
It is clear that the reason you should always use helper aliases like File.documentsDirectory is that Adobe is properly relying on the native OS to resolve the documents folder no matter what OS version you are running on.
-
4. Re: iOS 8 - FileStream throwing error 2038 on open for write?
Eljo.huckleberry Jul 23, 2014 1:24 AM (in response to Jeffrey Adams)You're right. I'll go with your solution and make sure my app update is released before iOS 8 sees the light of day publicly. Should fix this issue. Thanks for your help, the quick replies are much appreciated!
-
5. Re: iOS 8 - FileStream throwing error 2038 on open for write?
fideld Oct 13, 2014 8:20 AM (in response to Jeffrey Adams)A bit late to the party here - but with a related question.
I have an app that makes use of the same ..document path as above. After the upgrade to ios8 is there any way to access the files saved in this manner? (in order to manually relocate them to File.applicationStorageDirectory?
-
6. Re: iOS 8 - FileStream throwing error 2038 on open for write?
Eljo.huckleberry Oct 13, 2014 8:28 AM (in response to fideld)If you've been using the document path as I did before, you can simply access the data on any iOS version by using the File.documentsDirectory method. As outlined in a previous post of mine, you'll notice that it gives consistent results.
After which, you can store the data in the File.applicationStorageDirectory if you wish.
-
7. Re: iOS 8 - FileStream throwing error 2038 on open for write?
fideld Oct 14, 2014 12:53 AM (in response to Eljo.huckleberry)Hi Eljo - thanks for getting back to me on this...
I am having a really hard time confirming that what you wrote is actually working for me...
Let me just run my setup by you.
In my old version the first thing i do is to save the username in a config.xml
private var docDir:File = new File(File.applicationDirectory.nativePath + "/\.\./Documents");
var configFile:File = docDir.resolvePath("config.xml");
var configXML:XML = new XML("<?xml version='1.0' encoding='utf-8' ?><readapp />");
var fileStream:FileStream = new FileStream();
fileStream.open(configFile, FileMode.WRITE);
fileStream.writeUTFBytes(configXML);
fileStream.close();
Now in my updated version the first thing i do is to trace the different paths and to check if that config file exists
i try both
var docDir:File = new File(File.applicationDirectory.nativePath + "/\.\./Documents");
configFile = docDir.resolvePath("config.xml");
trace("Original config exists: " + configFile.exists.toString());
trace(configFile.nativePath)
trace(configFile.url)
docDir = File.documentsDirectory;
configFile = docDir.resolvePath("config.xml");
trace("documants dir config exists: " + configFile.exists.toString());
trace(configFile.nativePath)
trace(configFile.url)
On my ios7 ipad these two files are at the same position. However when i try this on my ios8 ipad the two files have different paths.
Are you telling me that during the upgrade to iOS8 apple moves the config.xml from: var/mobile/applications/[id]/Documents/config.xml to the new location: var/mobile/Containers/Data/Application/[id]/Documents/config.xml
?
-
8. Re: iOS 8 - FileStream throwing error 2038 on open for write?
Eljo.huckleberry Oct 14, 2014 1:46 AM (in response to fideld)Hey fideId, I didn't think it would work like that either at first. But like Jeffrey said: an upgrade to iOS8 will migrate all files to new locations as the folder structure has changed.
As long as you did not create any custom directories (which you didn't, as outlined by your code, you were targeting the official Documents directory), you're good to go by simply using the File.documentsDirectory method.
I can guarantee this works. And you don't necessarily have to move the files to the applicationStorageDirectory, by the way, but maybe you have other reasons for that (automatic iCloud backup, for example).
Only thing that sticks out a little is the path you're tracing. Although the same logic applies, my path included a 'private' folder which prevented writing to that location, but maybe you just left that part out.
Anyway, if you app is live already, the only downside for you right now is that users on iOS8 will probably experience errors as your old code is not compatible with it and the config.xml file cannot be created at that location.
Let me know if you need any more help.
-
9. Re: iOS 8 - FileStream throwing error 2038 on open for write?
fideld Oct 14, 2014 12:16 PM (in response to Eljo.huckleberry)Hi Eljo and again thanks again for your help. I don't know how i could leave out private/ as i double checked these urls... Its there as in your tests. I have one little question regarding just using the File.documentsDirectory as you mentioned. Do you know if files in that location are overwritten/removed when updating the app? I have had a hard time finding info on this and have read conflicting advice.
Best regards
Fidel
-
10. Re: iOS 8 - FileStream throwing error 2038 on open for write?
Eljo.huckleberry Oct 27, 2014 4:12 AM (in response to fideld)Hey, sorry for not getting back to you in a while. In my experience, the documents directory is perfectly fine and is never purged by the OS. For more information, see File System Programming Guide: File System Basics as it includes everything you need to know about this.
-
11. Re: iOS 8 - FileStream throwing error 2038 on open for write?
fideld Oct 29, 2014 2:14 AM (in response to Eljo.huckleberry)Hi Eljo,
No worries - i updated and submitted my app with the new directory.
Thank you very much for your help.

