iCloud +在iPhone Documents文件夹中存储媒体 [英] iCloud + Storage of media in iPhone Documents folder

查看:245
本文介绍了iCloud +在iPhone Documents文件夹中存储媒体的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我和许多开发人员一样,最近收到了Apple的一封电子邮件,声称我们应该将文档目录中的数据移动到另一个文件夹中,以便更加简化备份到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.

在最近的测试中,[你的应用]似乎在其Documents文件夹中存储了相当数量的数据。

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

自从执行iCloud备份每天通过Wi-Fi为每个用户的
iOS设备,通过最小化应用程序存储的数据量来确保最佳用户体验
非常重要。

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 ,instapaper成名,对问题有很好的理解,这是存储可下载文件的推荐位置在/ Library / Caches中。但问题是,只要操作系统确定设备的存储空间不足,就可以清除/ tmp和/ Caches。如果您的应用已清除,则您的应用下载并由您的用户存储的数据将会消失。当然,用户会责怪你而不是苹果。

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.

怎么办?

推荐答案

iOS 5.0.1引入了一个标志来解决这个问题:

iOS 5.0.1 introduced a flag to address this issue:

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

他们建议在/ Library / like / Library / PrivateDocs中创建一个文件夹,然后将文件放在那里。但是,您还必须在它们上设置不备份标志,因为/ Library中的每个文件除了/ Library / Cache或tmp中的文件都默认备份。使用以下命令在PrivateDocs文件夹上设置标志:

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;
}

这篇关于iCloud +在iPhone Documents文件夹中存储媒体的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆