Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

iOS 5 does not allow to store downloaded data in Documents directory?

I have made an application for my client by keeping target iOS as 4.
But since the application still not submitted to Apple store, my client is planning to upgrade it for iOS 5.0.

For this I read the guideline from Apple and found that "Only user-generated data or that cannot otherwise be recreated by your application, should be stored in the /Documents directory and rest should be stored to /Library/Caches directory"

In my application, I am using server model of in-app purchase for non-consumable product. For this I am storing all my downloaded data (which are basically books or magazines) to Documents directory. The Database is also present in the same directory which contains the details about the downloaded products.

My question is,
1. Should I have to change my code to store the downloaded data to Library/Caches directory instead of to the Documents directory?
2. Where should my database file be placed (to Documents or Caches)?

If I put it products in the Caches then I have to change the logic of retrieval also, since it is considered that if record is present in database, there is no need change the existence of the file and it directly opens it when user clicks on the magazine.

Kindly guide me on this issue.
Thanks in advance.

UPDATED:
I am updating this for those who are still not sure about this problem.
Using the guideline of accepted answer, I have implemented this in 2 of my applications and submitted them to Apple Store. Both were approved in review.
This may promote that the solution suggested in the accepted answer is correct.

like image 885
Naved Avatar asked Nov 21 '11 09:11

Naved


4 Answers

Here are the trade-offs:

  • If you put your files in the Documents directory then they are backed up to iTunes or iCloud but if they are too big and it's possible to download the files again then Apple may reject your app
  • If you put your files in the Cache directory then they won't be backed up and Apple won't reject your app. However, when iOS 5 gets low on space it may delete all the files in there.

However, with iOS 5.0.1 there is a third option:

  • Put files in Documents but flag them so that they are not backed up. There's a technote (QA1719) on how to do this.

I think this is probably the best answer for you.

like image 128
Stephen Darlington Avatar answered Nov 11 '22 04:11

Stephen Darlington


1. Should I have to change my code to store the downloaded data to Library/Caches directory instead of to the Documents directory? = Yes, you need to store the downloaded data to Library/Caches directory.

2. Where should my database file be placed (to Documents or Caches)? = You can keep the database in Documents directory.

like image 41
Himanshu A Jadav Avatar answered Nov 11 '22 04:11

Himanshu A Jadav


One app I know was once rejected because of this. Storing downloadable data in Documents dir is not recommended. The logic behind it is that your data should not unnecessarily inflate the app directory. This app directory is backed up in iCloud, so inflated app directory will cause more data to be saved in iCloud.

If data can be downloaded again, like magazines, books pdf etc. Then keep it in Caches directory. Of course you can store pointers to data (like URLs etc) in the Documents directory so that the user can retrieve them later.

To answer your questions:

  1. Yes, change your code to load DB from Documents and Data from Caches.
  2. Keep database in Documents

You'll have to add code to check if a document in DB exists in Caches, if it doesn't your app should download it again.

like image 29
Mridul Kashatria Avatar answered Nov 11 '22 04:11

Mridul Kashatria


On top of the suggestion that you should keep the data in cache directory, there is a concern that you should keep in mind when keeping the data into cache folder:

Whenever iOS feels the memory crunch it deletes all the cache and temp folder. Problem is described here in detail To protect these directory not to delete and keep everything for lifetime you should use the attribute that will keep the mentioned directory safe. Solution is here:

like image 3
UPT Avatar answered Nov 11 '22 04:11

UPT