即使在执行addSkipBackupAttributeToItemAtURL时,仍然可以备份到iCloud?

我最近的iOS应用程序刚刚被拒绝,因为应用程序正在存储数据的文档,所以它由iCloud备份,这是不允许的,因为数据是从服务器下载。

我正在尝试重build代码,并将数据存储在一个名为Application Application Support的文件夹中时遇到了困难。

但即使我使用addSkipBackupAttributeToItemAtURL它仍然显示为备份到iCloud。

我只针对5.1,所以这不是一个版本问题。

我在下面添加了受影响的代码:

NSString *newPath = [NSMutableString stringWithFormat:@"%@/Library/Application Support/", NSHomeDirectory()]; if (![[NSFileManager defaultManager] fileExistsAtPath:newPath]) //Does directory already exist? { if (![[NSFileManager defaultManager] createDirectoryAtPath:newPath withIntermediateDirectories:NO attributes:nil error:&error]) { NSLog(@"Create directory error: %@", error); } } NSString *guidesPath = [newPath stringByAppendingPathComponent:@"/Guides"]; if (![[NSFileManager defaultManager] fileExistsAtPath:guidesPath]) //Does directory already exist? { if (![[NSFileManager defaultManager] createDirectoryAtPath:guidesPath withIntermediateDirectories:NO attributes:nil error:&error]) { NSLog(@"Create directory error: %@", error); } } NSString *dataPath = [guidesPath stringByAppendingPathComponent:dbName]; if (![[NSFileManager defaultManager] fileExistsAtPath:dataPath]) { if (![[NSFileManager defaultManager] createDirectoryAtPath:dataPath withIntermediateDirectories:NO attributes:nil error:&error]) { NSLog(@"Create directory error: %@", error); } } NSString *newGuidesPath = [dataPath stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding]; NSURL *guidesURL = [NSURL URLWithString:newGuidesPath]; [self addSkipBackupAttributeToItemAtURL:guidesURL]; NSString* path = [dataPath stringByAppendingPathComponent: [NSString stringWithString: finalName] ]; if (![fileManager fileExistsAtPath:path]) { [myData writeToFile:path atomically:YES]; NSString *docFile = [dataPath stringByAppendingPathComponent: @"guideid.txt"]; [[guideID dataUsingEncoding:NSUTF8StringEncoding] writeToFile:docFile atomically:NO]; DLog(@"Saved database here:%@", path); }else{ DLog(@"Already exists, no need to copy"); } } 

  - (BOOL)addSkipBackupAttributeToItemAtURL:(NSURL *)URL { assert([[NSFileManager defaultManager] fileExistsAtPath: [URL path]]); NSError *error = nil; BOOL success = [URL setResourceValue: [NSNumber numberWithBool: YES] forKey: NSURLIsExcludedFromBackupKey error: &error]; if(!success){ NSLog(@"Error excluding %@ from backup %@", [URL lastPathComponent], error); } return success; } 

实际上find了一个解决scheme,我已经编码了不需要的URL。 刚刚添加到该文件夹

  NSURL *guidesURL = [NSURL fileURLWithPath:guidesPath]; [guidesURL setResourceValue:[NSNumber numberWithBool:YES] forKey:NSURLIsExcludedFromBackupKey error:NULL]; 

并跳过排除方法,只是标记在代码中,这似乎工作。

您是否尝试从icloud设置在您的设备上创build新的备份?