IOS 5 does not allow you to save downloaded data in the Documents folder?

I made a request for my client, keeping the target iOS as 4.
But since the application is still not sent to the Apple Store, my client plans to update it for iOS 5.0.

To do this, I read the manual from Apple and found that "only user data or which otherwise could not be recreated by your application should be stored in the / Documents directory, and rest should be stored in the / Library / Caches directory"

In my application, I use the in-app purchase server model for a non-consuming product. To do this, I save all the data you uploaded (mainly books or magazines) to the Documents folder. The database is also present in the same directory that contains information about downloaded products.

My question is
1. Do I have to change my code to store the downloaded data in the Library / Caches directory, and not in the Documents directory?
2. Where should my database file be located (in Documents or Caches)?

If I put it in caches, then I will also have to change the extraction logic, since it is believed that if the record is present in the database, there is no need to change the existence of the file, and it opens immediately when the user clicks on the log.

Please help me in this matter.
Thanks in advance.

UPDATED:
I am updating this for those who are still not sure about this issue.
Using the recommendation of the accepted answer, I implemented this in two of my applications and sent them to the Apple Store. Both were approved in the review.
This can help ensure that the solution proposed in the accepted answer is correct.

+49
objective-c iphone ios5 in-app-purchase
Nov 21 '11 at 9:02
source share
6 answers

Here are the tradeoffs:

  • If you put your files in the Documents directory, they will be copied to iTunes or iCloud, but if they are too large and you can download the files again, Apple may reject your application.
  • If you put your files in the Cache directory, they will not be copied, and Apple will not reject your application. However, when iOS 5 becomes small in space, it can delete all files there.

However, with iOS 5.0.1 there is a third option:

  • Place files in documents, but mark them so that they are not copied. Where this is done, technoth ( QA1719 ).

I think this is probably the best answer for you.

+57
Nov 21 2018-11-11T00:
source share

1. Do I have to change my code to store the downloaded data in the Library / Caches directory, and not in the Documents folder? = Yes, you need to save the downloaded data to the Library / Caches directory.

2. Where should my database file be located (in Documents or Caches)? = You can save the database in the "Documents" folder.

+7
Nov 21 '11 at 9:13
source share

One of the applications that I know was once rejected because of this. Storing uploaded data in Document dir is not recommended. The logic behind this is that your data should not over-inflate the application directory. This application directory is backed up in iCloud, so an inflated application directory will cause more data to be saved in iCloud.

If the data can be downloaded again, such as magazines, pdf books, etc. Then save them in the Caches directory. Of course, you can store pointers to data (for example, URLs, etc.) in the Documents directory so that the user can download them later.

To answer your questions:

  • Yes, change your code to load a database from documents and data from caches.
  • Store database in documents

You will need to add code to check if the document exists in the database in caches if its application does not load it again.

+6
Nov 21 '11 at 9:10
source share

In addition to the assumption that you should store data in the cache directory, there is a concern that you should keep in mind when storing data in a cache folder:

Whenever iOS feels a crunch of memory, it deletes the entire cache folder and temporary folder. The problem is described in detail here. To protect this directory, so as not to delete or store everything for life, you should use an attribute that will keep the specified directory safe. The solution is here:

+4
Nov 21 2018-11-11T00:
source share

I searched for the same query and I have a solution. According to Apple's data storage documentation, a developer can store data in the cache, even if the user wants to save this data in a low memory situation .develper just needs to set the Do not back up flag.

 Use the "do not back up" attribute for specifying files that should remain on device, even in low storage situations. Use this attribute with data that can be recreated but needs to persist even in low storage situations for proper functioning of your app or because customers expect it to be available during offline use. This attribute works on marked files regardless of what directory they are in, including the Documents directory. These files will not be purged and will not be included in the user iCloud or iTunes backup. Because these files do use on-device storage space, your app is responsible for monitoring and purging these files periodically. 

For more information, follow this link.

Use the code snippet below to set the Do not back up flag.

import <sys/xattr.h>

 - (BOOL)addSkipBackupAttributeToItemAtURL:(NSURL *)URL { if (&NSURLIsExcludedFromBackupKey == nil) { // iOS <= 5.0.1 const char* filePath = [[URL path] fileSystemRepresentation]; const char* attrName = "com.apple.MobileBackup"; u_int8_t attrValue = 1; int result = setxattr(filePath, attrName, &attrValue, sizeof(attrValue), 0, 0); return result == 0; } else { // iOS >= 5.1 NSError *error = nil; [URL setResourceValue:[NSNumber numberWithBool:YES] forKey:NSURLIsExcludedFromBackupKey error:&error]; return error == nil; } 

}

URL is the path of Data.

+3
01 Oct 2018-12-12T00:
source share

I made a request for my client, setting the target iOS to 4. But since the application is still not sent to the Apple store, the client plans to update it for iOS 5.0

Another option (if you are only going to support iOS 5) is to use NewsstandKit. Thus, only selected issues of the magazine will be removed by iOS at a low level on the disk. My understanding is that iOS will remove selected issues based on the last read and possibly the size.

If you do not use the newsstand and the target application, all problems will be removed.

+2
Nov 23 2018-11-11T00:
source share



All Articles