2012年5月15日火曜日

Data in the Documents folder


 

I was really surprised when one of my apps was rejected by Apple when all I did was update the icon and the app have past previous reviews with flying colors. It seems like there's a new rule about data you store in the /Documents folder.

All files in the Documents folder are backed up to iCloud and such files that can be re-downloaded or re-created should not be stored there. For obvious reasons, to not waste those precious 5 GB we have by default. However, if you put your data in Caches folder or tmp folder, it might be deleted in low storage situations so there is a new solution from iOS 5.0.1.

This allows you to put files that you generate, like a read-only database, to the Documents folder without having it backed up to iCloud.

Here's a snippet from iOS Developer Library

Q:  My app has a number of files that need to be stored on the device permanently for my app to function properly offline. However, those files do not contain user data and don't need to be backed up. How should I store those files in iOS 5?

A: Starting in iOS 5.0.1 a new "do not back up" file attribute has been introduced allowing developers to clearly specify which files should be backed up, which files are local caches only and subject to purge, and which files should not be backed up but should also not be purged. In addition, setting this attribute on a folder will prevent the folder and all of its contents from being backed up.

Important The new "do not back up" attribute will only be used by iOS 5.0.1 or later. On iOS 5.0 and earlier, applications will need to store their data in <Application_Home>/Library/Caches to avoid having it backed up. Since this attribute is ignored on older systems, you will need to insure your app complies with the iOS Data Storage Guidelines on all versions of iOS that your application supports.

How to set the attribute

#include <sys/xattr.h>

- (BOOL)addSkipBackupAttributeToItemAtURL:(NSURL *)URL
{
    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;
}
140 180 iOS

記載されている会社名、および商品名等は、各社の商標または登録商標です。

0 コメント:

コメントを投稿

Related Posts Plugin for WordPress, Blogger...