我不想将任何内容备份到 iCloud。但是,我的数据无法重新创建,因此我需要将其放置在应用程序的文档目录中。对于每个文件,我都执行了标准:
- (BOOL)addSkipBackupAttributeToItemAtURL:(NSURL *)URL
{
if (&NSURLIsExcludedFromBackupKey == nil) { // iOS <= 5.0.1
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;
} else { // iOS >= 5.1
return [URL setResourceValue:[NSNumber numberWithBool:YES] forKey:NSURLIsExcludedFromBackupKey error:nil];
}
}
我那里有 5mB 的数据。但我的应用程序仍在 iCloud 中注册 0.2kB(通过设置 -> iCLoud -> 管理存储)。所以,为了确定,我这样做了:
-(void)resetBackupAttributes {
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *documentsDirectory = [paths objectAtIndex:0];
NSArray *fileListAct = [[NSFileManager defaultManager] contentsOfDirectoryAtPath:documentsDirectory error:nil];
for (NSString *path in fileListAct) {
[self addSkipBackupAttributeToItemAtURL:[NSURL fileURLWithPath:path]];
}
NSArray *paths2 = NSSearchPathForDirectoriesInDomains(NSCachesDirectory, NSUserDomainMask, YES);
NSString *cacheDirectory = [paths2 objectAtIndex:0];
NSArray *fileListCache = [[NSFileManager defaultManager] contentsOfDirectoryAtPath:cacheDirectory error:nil];
for (NSString *path in fileListCache) {
[self addSkipBackupAttributeToItemAtURL:[NSURL fileURLWithPath:path]];
}
NSArray *paths3 = NSSearchPathForDirectoriesInDomains(NSPreferencePanesDirectory, NSUserDomainMask, YES);
NSString *preferencesDirectory = [paths3 objectAtIndex:0];
NSArray *fileListPref = [[NSFileManager defaultManager] contentsOfDirectoryAtPath:preferencesDirectory error:nil];
for (NSString *path in fileListPref) {
[self addSkipBackupAttributeToItemAtURL:[NSURL fileURLWithPath:path]];
}
}
还有0.2kB!我有什么遗漏的吗?不管怎样,都会备份少量数据,比如目录树之类的吗?我真正想知道的是,这 0.2kB 会让我因为不遵循数据存储准则而被拒绝吗?
最佳答案
好的,我会将我的评论放入答案中:
is it possible that your apps default plist gets backed up in the cloud? - BUT you could hook up a proxy between your iOS (simulator) and the internet. Just catch all outgoing data and see whats actually get transmitted ;). e.g. SquidMan
这是SquidMan的链接以防万一……
正如你所说,你也认为它是 plist。您可以通过设置一个带有一些垃圾数据的 key 来验证这一点,并查看总量是否上升。 ;)
关于iphone - 少量不需要的数据进入 iCloud,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10184543/