作者热门文章
- android - RelativeLayout 背景可绘制重叠内容
- android - 如何链接 cpufeatures lib 以获取 native android 库?
- java - OnItemClickListener 不起作用,但 OnLongItemClickListener 在自定义 ListView 中起作用
- java - Android 文件转字符串
我有一个应用程序可以下载大量照片并将它们存储在 Documents 文件夹的子文件夹中,这在 iOS 5.1 之前显然没问题
现在 Apple 告诉我需要将它们存储在其他地方或以某种方式将它们标记为不用于备份。这是一个应用程序更新,因此对于我的大多数用户来说,数据已经存在于这些子文件夹中。
如何让 iOS 跳过我的 Documents 子文件夹中的所有文件或跳过 Documents 文件夹中的特定文件?
按照他们的建议将所有文件移动到缓存中将是一项艰巨的任务。
我读过这个,但我不确定我应该在哪里实现这个: https://developer.apple.com/library/ios/#qa/qa1719/_index.html
最佳答案
您可以使用 NSFileNanager 列出所有文件,然后调用您喜欢的建议函数。您的代码类似于:
// From Apple FAQ
#import <sys/xattr.h>
- (BOOL)addSkipBackupAttributeToItemAtURL:(NSURL *)URL
{
assert([[NSFileManager defaultManager] fileExistsAtPath: [URL path]]);
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;
}
- (void) addSkipBackupAttributeToItemsInFolder:(NSString*)folder
{
NSFileManager *fm = [NSFileManager defaultManager];
NSArray *dirContents = [fm contentsOfDirectoryAtPath:folder error:nil];
for (int curFileIdx = 0; curFileIdx < [dirContents count]; ++curFileIdx)
{
NSString* curString = [folder stringByAppendingPathComponent:[dirContents objectAtIndex:curFileIdx]];
NSURL* curFileUrl = [NSURL fileURLWithPath:curString];
[self addSkipBackupAttributeToItemAtURL: curFileUrl];
}
}
你会这样使用它:
NSString *documentsDirectory = [NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES) objectAtIndex:0];
[self addSkipBackupAttributeToItemsInFolder:documentsDirectory];
关于iphone - 应用程序因数据存储而被拒绝 - 如何让它忽略文件夹中的所有文件?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10822429/
我制作了一个函数,可以一次绘制来自多个因子分析的载荷,也可以绘制变量不完全重叠(或根本不重叠)的载荷。它可以正常工作,但有时在各个分析中因子加载是相同的,这意味着这些点会相互重叠绘制。 library
我是一名优秀的程序员,十分优秀!