2.23 - Apps must follow the iOS Data Storage Guidelines
On launch and content download, your app stores 6.99MB, which does not comply...
核心问题:可再生数据未标记排除备份,导致 iCloud 备份体积超标。
| 目录 | 用途 | 备份行为 | 合规要求 |
|---|---|---|---|
| Documents | 用户创建内容(文档、数据库) | ✅ 备份 | 仅存用户不可再生数据 |
| Library/Caches | 缓存、可再生下载数据 | ❌ 不备份 | 系统可随时清理 |
| tmp | 临时文件 | ❌ 不备份 | 应用自行清理 |
| Library/Application Support | 应用运行必需数据 | ✅ 备份 | 需标记排除备份 |
NSURLIsExcludedFromBackupKey → 错误! 用户数据库应允许备份[NSURL URLWithString:url] // 无法设置资源值!
NSURL *fileURL = [NSURL fileURLWithPath:path]; // 必须用 fileURLWithPath
NSError *error = nil;
BOOL success = [fileURL setResourceValue:@YES forKey:NSURLIsExcludedFromBackupKey error:&error];
if (!success) {
NSLog(@"设置排除备份失败: %@", error);
}
// 1. 用户核心数据(数据库、文档) → Documents,允许备份
NSString *docPath = [NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES).firstObject
stringByAppendingPathComponent:@"user.db"];
// 2. 可再生下载数据(图片、离线包) → Caches,天然不备份
NSString *cachePath = [NSSearchPathForDirectoriesInDomains(NSCachesDirectory, NSUserDomainMask, YES).firstObject
stringByAppendingPathComponent:@"downloads"];
// 3. 运行必需但可再生数据(配置、Token) → App Support + 排除备份
NSString *supportPath = [NSSearchPathForDirectoriesInDomains(NSApplicationSupportDirectory, NSUserDomainMask, YES).firstObject
stringByAppendingPathComponent:@"config.plist"];
NSURL *supportURL = [NSURL fileURLWithPath:supportPath];
[supportURL setResourceValue:@YES forKey:NSURLIsExcludedFromBackupKey error:nil];
// 4. 临时文件(录音、压缩包) → tmp,用完即删
NSString *tmpPath = [NSTemporaryDirectory() stringByAppendingPathComponent:@"recording.m4a"];
NSURLIsExcludedFromBackupKey 设置成功