Just to echo Justin’s experience on this, we have also had app submissions rejected by Apple for storing unnecessary files (e.g. downloadable content files) in /Library/Documents. This directory should only be used for storing persistent data like save game files or user preferences - these can then be backed up automatically via iCloud.
Other files like downloadable content or advertisement assets should go into either /Library/Caches or /Library/Application Support. Note that files in /Library/Caches may be deleted by the operating system if disk space is running low. It would be best to allow developers to choose which of these 3 directories to use.
How about changing getWriteablePath() to take an enum? e.g.
I’m currently using CCFileUtils::sharedFileUtils()->getWriteablePath() but as Minggo said before this returns the path to /Caches which is apparently unsafe. Does anyone know how to get the path to /Documents on iOS?
is anybody knows how to save and retrieve image file in android…my getwriteablepath return path in format of /data/data/<package/files but i am not able to read it…
not sure if this is still an open topic for Cocos2d-x, we at V-Play ( http://v-play.net ) also had a deeper look into the topic of writable paths. Our game engine defines four location types (explanation is iOS-specific as of iOS 5.1 and above):
The locations can be selected depending on the desired behaviour in respect to BACKUP (iCloud back up), PURGE (auto purging files if the device runs out of memory) and PUBLIC (users can probably read the files with iTunes):
HomeLocation
BACKUP
PURGE
PUBLIC
For user generated data, backed-up to iCloud, can be read with iTunes
TempLocation
BACKUP
PURGE
PUBLIC
All application specific files that need not persist between application launches must be put here and should be deleted at application exit.
DataLocation
BACKUP
PURGE
PUBLIC
For configuration files, backed-up to iCloud, not purged
~~> possible to apply the com.apple.MobileBackup extended attribute to prevent from backing up to iCloud CacheLocation
~~ BACKUP
PURGE
PUBLIC
Can be purged when devices run out of (physical) memory, so must be re-downloaded in some cases
So to summarize I would suggest:
For save games, screenshots and other user-generated content ~~> DocumentsLocation
~~ For downloadable content which can be fetched from web again -> CacheLocation or DataLocation with “no backup” file attribute
On Android there are the methods getFilesDir(), getCacheDir() (and there external representations getExternalFilesDir(), getExternalStoragePublicDirectory(), getExternalCacheDir()) like already stated above.
Hope this helps a little bit, cross-platform storage paths are sometimes a real mess!
I was also having this problem on Android where my file was not created inside getWritablePath. Using a Root Explorer, I’ve found that this path wasn’t being created!
After taking a look at android documentation into file storage, I’ve found that the correct way to get the path is: Cocos2dxHelper.java
This way the file directory will be created if it doesn’t exists already. I’ve tested and it’s working in my test devices. The created path now looks like this:
08-01 14:24:16.832: D/cocos2d-x debug info(10676): Save File Path: /data/data/com.my.game/app_data/my.file
For iOS:
Documents : for some data that created by USER, it means that these data cannot be recreated by program, such as some config files for user.
Library/Caches: some data that can be recreated by program, such as magazines, books.
So , the getWritablePath should return the Library/Caches.
Sorry for bumping this topic but… Is this solved? Is it save to use getWritablePath? edit
I think I should be more specific. I want to save something permanent for android and ios and win32. What Path should i use?
Hi, I checked FileUtilsIOS.mm and code for getWritablePath() is same in v3.3 and 2.2.6.
But I figured out, that the directory /var/mobile/Documents was missing on my device. I created the Documents folder in /var/mobile/ and set folder owner to mobile. After that, the file can be created and everything is fine.
Does anybody know why this folder was missing on my device?