iOS DocumentsDirectory

Good Day

So far I am having no problem in writing files in the DocumentsDirectory wether Android or iOS.

The question is, iOS has a policy that, you cannot write files in the DocumentsDirectory. They suggest that to put it in the CachesDirectory. The problem is, in Android I can clear the cache of my app, so yeah all of my record will be lost in an instant, I don’t know if iOS can do that. So are there any other way to allow writing files in an iOS device with my app? BTW the file is used to store my JSON data for the map content of my game.

God Speed

Let me clairify… You’re more than free to write to system.DocumentsDirectory.  Apple doesn’t mind as long as you follow the rules.  The main thing you need to understand is that system.DocumentsDirectory gets backed up to iCloud automatically.  Users don’t want their iCloud quote being taken up by junk files your app downloads or creates.  They only want the important parts that need backed up (i.e. settings, account info).  Because of that, Apple has these rules.

1.  If it can be downloaded, it needs to go to system.CachesDirectory.  The idea is if it gets cleared off of the device, it can be fetched again.  No need to back this stuff up.

  1. If it’s big, or does not need to be backed up, you have to set a flag on the file so that iCloud won’t back it up.  See: http://docs.coronalabs.com/api/library/native/setSync.html

Apple will reject your app if you write large files out (I don’t know what “Large” is…) that are not marked as “Don’t back up”.  They will reject you if downloaded files go to system.DocumentsDirectory if they can be retrieved again (99.9% of the time they can)

How to deal with this for Android?  Well Android doesn’t have these rules.  system.CachesDirectory is actually mapped to system.TemporaryDirectory.  All you have to do is put a test in when you save files that checks to see if your iOS and do it one way, or if you’re on Android do it the other.

Rob

Ohh… so I can stick with CachesDirectory. My issue was on Android only cause  of the privileges of the user to clear its cache, I tought it will go to CachesDirectory, but instead it is treated as TemporaryDirectory. Well that’s good news, so yeah, Thanks! :), but still gonna try the DocumentsDirectory, for consistency.

Let me clairify… You’re more than free to write to system.DocumentsDirectory.  Apple doesn’t mind as long as you follow the rules.  The main thing you need to understand is that system.DocumentsDirectory gets backed up to iCloud automatically.  Users don’t want their iCloud quote being taken up by junk files your app downloads or creates.  They only want the important parts that need backed up (i.e. settings, account info).  Because of that, Apple has these rules.

1.  If it can be downloaded, it needs to go to system.CachesDirectory.  The idea is if it gets cleared off of the device, it can be fetched again.  No need to back this stuff up.

  1. If it’s big, or does not need to be backed up, you have to set a flag on the file so that iCloud won’t back it up.  See: http://docs.coronalabs.com/api/library/native/setSync.html

Apple will reject your app if you write large files out (I don’t know what “Large” is…) that are not marked as “Don’t back up”.  They will reject you if downloaded files go to system.DocumentsDirectory if they can be retrieved again (99.9% of the time they can)

How to deal with this for Android?  Well Android doesn’t have these rules.  system.CachesDirectory is actually mapped to system.TemporaryDirectory.  All you have to do is put a test in when you save files that checks to see if your iOS and do it one way, or if you’re on Android do it the other.

Rob

Ohh… so I can stick with CachesDirectory. My issue was on Android only cause  of the privileges of the user to clear its cache, I tought it will go to CachesDirectory, but instead it is treated as TemporaryDirectory. Well that’s good news, so yeah, Thanks! :), but still gonna try the DocumentsDirectory, for consistency.