Graphics Programs Reference
In-Depth Information
For the More Curious: iCloud Backups
Although not an explicit feature of iCloud, iOS supports backing up the contents of a
device in the cloud. Part of the backup process synchronizes the Documents and
Library/Preferences directories of each application sandbox. This is pretty neat,
but you can't go hog wild. This ability to back up data in Documents/ in the cloud has
led to a new requirement for applications: you can't store too much data in the Docu-
ments directory on pain of your application being rejected by the App Store.
Of course, “too much data” is frustratingly vague, but the general rule is only store in
Documents/ what really needs backing up and not what can be recreated. Data that can
be recreated should be stored in Library/Caches/ instead of Documents/ .
However, there is a problem with this rule. The system can purge the contents Library/
Caches/ when an application is running low on disk space, and it can do so without
warning. Now, if an application can recreate its caches from another server, it's not a big
deal if this directory gets purged - you just download the content again. However, some ap-
plications cache content for offline use. For example, an application could download web
articles so that the user can read them on a plane. If the application is offline, data that gets
purged can't be recreated.
If you need to store potentially large amounts offline content indefinitely, the fix is to put
the data in Documents/ and set a special flag that prevents the file or the folder and its
contents from being backed up. This protects the data from being purged and keeps the
App Store happy. You set this flag like so:
NSArray *docsDirs = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory,
NSUserDomainMask,
YES);
NSString *path = [[docsDirs objectAtIndex:0]
stringByAppendingPathComponent:@"somefile"];
[data writeToFile:path atomically:YES];
NSURL *url = [NSURL fileURLWithPath:path];
[url setResourceValue:[NSNumber numberWithBool:YES]
forKey:NSURLIsExcludedFromBackupKey
error:nil];
The important bit here is the key NSURLIsExcludedFromBackupKey . This key can
be set on any URL (file or folder) in an application's sandbox and prevent it from being
Search WWH ::




Custom Search