my app has downloadable in-app purchases. When the content is downloaded I am storing it right now on the documents directory. But I know Apple is nitpick and will probably reject my app because content that could be restored should not be stored on the documents directory, that means, will be saved to icloud.
I thought of using temp or cache directories but these can be emptied any time when iOS needs space.
Where should I save it?
I also read the document folder is for user generated content and have been advised to use the cache folder despite of the fact that your data can be deleted when needed. I also read that using the document folder with the no backup flag can be a choice when targeting ios 5.1 and up.
See iOS 5.0.1 : How to verify that the folder is marked as "Do not back up" for iCloud?
Adding the "Do Not Backup" attribute to a folder hierarchy in iOS 5.0.1
The
Documents
directory can only be used for user generated data that cannot be downloaded (including potential databases that contain user selectable settings and similar), so you're right, you will probably be rejected if you store downloadable content there.The way I've done it is to store the downloaded data in
Cache
(which as you say can be cleared at any time when space is low), and store a small piece of data inDocuments
that says that the content should be inCache
. WhenDocuments
says that the data should be there and it's not, I'll notify the user that the content has been automatically removed by iOS due to space issues, and offer the user to download it again.That way, if the user does not use the content for a while, he can reuse the space on his device for other things, and can still download the content again at will. Just like I'd want an app to work if I were the user :)
EDIT: You can put them in
Library
if you need them to be always persistent, but remember to mark them as not backed up to iCloud or you'll most likely get the same rejection.The documentation here https://developer.apple.com/library/ios/documentation/NetworkingInternet/Conceptual/StoreKitGuide/Chapters/DeliverProduct.html#//apple_ref/doc/uid/TP40008267-CH5-SW5
says the
Documents
folder is the place to move the content if you want it to persist.