gpt4 book ai didi

iphone - 应用程序因数据存储而被拒绝 - 如何让它忽略文件夹中的所有文件?

转载 作者:可可西里 更新时间:2023-11-01 03:55:19 24 4
gpt4 key购买 nike

我有一个应用程序可以下载大量照片并将它们存储在 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/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com