Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

iCloud + Storage of media in iPhone Documents folder

Tags:

ios

iphone

icloud

I, like many developers, got an email from Apple recently that stated we should move our data from the documents directory into another folder to permit more streamlined backup to iCloud.

In recent testing it appears that [your app] stores a fair amount of data in its Documents folder.

Since iCloud backups are performed daily over Wi-Fi for each user's iOS device, it's important to ensure the best possible user experience by minimizing the amount of data being stored by your app.

Marco Arment, of instapaper fame, has a good take on the issue, which is that the recommended location for storing downloadable files is in /Library/Caches. However, the problem is that both /tmp and /Caches can be 'cleaned' anytime the OS decides that the device is running low on storage. If your app is cleaned then the data downloaded by your app and stored by your user is gone. Naturally, the user will blame you and not Apple.

What to do?

like image 283
Michael Morrison Avatar asked Oct 14 '11 03:10

Michael Morrison


People also ask

What is stored in documents on iCloud?

You can store documents, images and spreadsheets using iCloud Drive; you can also keep files and folders up-to-date across devices, work on them, and access these items from anywhere. On iOS devices, you access your iCloud Drive through the Files app. Open Files and you'll find iCloud Drive as a location.

Where are iPhone documents stored?

In the Files app, you can find: Files on the iPhone, iPad, or iPod touch that you're using. Files in iCloud Drive, including Pages, Numbers, and Keynote documents. Files in other cloud services and apps, like Box, Dropbox, OneDrive, Adobe Creative Cloud, Google Drive, and more.


2 Answers

iOS 5.0.1 introduced a flag to address this issue:

https://developer.apple.com/library/ios/#qa/qa1719/_index.html

Their recommendation is to create a folder in /Library/ like /Library/PrivateDocs , and put your files there. However you will also have to set a "do not backup" flag on them as every file in /Library except for those in /Library/Cache or tmp are backed up by default. Set the flag on PrivateDocs folder with this command:

#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;
}
like image 123
BadPirate Avatar answered Nov 03 '22 00:11

BadPirate


Library/Caches is probably a good answer for many apps. Especially when the app will work fine is cached data is lost and clearing the cache does not also destroy all record of what data a user might have elected to cache and where it can be re-obtained from.

For apps which have data which does not belong in Caches consider Library/Application Support.

http://developer.apple.com/library/ios/documentation/FileManagement/Conceptual/FileSystemProgrammingGUide/FileSystemOverview/FileSystemOverview.html#//apple_ref/doc/uid/TP40010672-CH2-SW1

Application Support:

Use this directory to store all application data files except those associated with the user’s documents. For example, you might use this directory to store application-created data files, configuration files, templates, or other fixed or modifiable resources that are managed by the application. An application might use this directory to store a modifiable copy of resources contained initially in the application’s bundle. A game might use this directory to store new levels purchased by the user and downloaded from a server.

All content in this directory should be placed in a custom subdirectory whose name is that of your application’s bundle identifier or your company.

In iOS, the contents of this directory are backed up by iTunes.


Unfortunately the Application Support directory is still backed up and falls under Apple's new data storage guidelines. Depending on how sensitive reviewers choose to be about total backed up file size this may still lead to rejections.

like image 39
Jonah Avatar answered Nov 03 '22 01:11

Jonah