IOS存储问题

时间:2016-05-29 20:50:54

标签: ios ios9 xcode7

抱歉我的英文。我有一个存储问题,Apple拒绝了我的应用程序。我在我的应用程序中使用sqlite db并从bundle中复制它,因为我需要db中的更新记录。有很多关于此的信息,但它不适合我!

我尝试将NSURLIsExcludedFromBackupKey与目录NSApplicationSupportDirectorylibrary/caches和其他目录一起使用,但它无法正常工作,我看到我的应用存储大小为db,如果我不要复制我的数据库我没有在存储中看到我的应用程序,但我需要一份副本。

我必须做什么?

我使用iOs9,xCode 7:

BOOL success;
NSFileManager *fileManager = [NSFileManager defaultManager];
NSError *error;
stringByAppendingPathComponent:@"db_words"];
NSString *defaultDBPath = [[[NSBundle mainBundle] resourcePath] 
stringByAppendingPathComponent:@"db_words"];
NSURL *applicationSupportDirectory = [[NSFileManager defaultManager]     URLForDirectory:NSApplicationSupportDirectory
                                                                     inDomain:NSUserDomainMask
                                                                   appropriateForURL:nil
                                                                      create:YES
                                                                       error:&error];

NSURL *referenceFolder = [applicationSupportDirectory     URLByAppendingPathComponent:@"Reference" isDirectory:YES];

success = [[NSFileManager defaultManager] createDirectoryAtPath:[referenceFolder path]
                               withIntermediateDirectories:YES
                                                attributes:nil
                                                     error:&error]

success = [referenceFolder setResourceValue:@YES forKey: NSURLIsExcludedFromBackupKey error: &error];

if(!success){
    NSLog(@"KCDM: Error excluding %@ from backup %@", referenceFolder, error);
}


NSString * writableDBPath = [referenceFolder.path stringByAppendingPathComponent:@"db_words"];
success = [fileManager copyItemAtPath:defaultDBPath toPath:writableDBPath error:&error];
if (!success)
    NSAssert1(0, @"Failed to create writable database file with message '%@'.", [error localizedDescription]);

return writableDBPath;

1 个答案:

答案 0 :(得分:1)

由于On启动和内容下载不是由用户启动"用户生成的数据"但是通过你在午餐时的申请,Apple想知道"不要备份"策略(到iCloud)应用此下载的数据以及是否可以重新创建此数据? /或应保留在设备上,即使在低存储情况下也是如此。所有这些情况都得到了很好的解释iOS Data Storage Guidelines

因此,为您提供app-launch-downloaded-data的政策将解决您的问题......

在您的情况下,您可能只需要skipBackup for applicationSupportDirectory,因此在if (condition == true) { jQuery(".onoffswitch-switch").trigger('click'); } appDelegate添加跳过备份:

didFinishLaunchingWithOptions
  

使用"不要备份"用于指定应保留在设备上的文件的属性,即使在低存储情况下也是如此。用这个   属性包含可以重新创建但仍需要持久化的数据   低存储情况,以确保您的应用程序正常运行或因为   客户希望在离线使用时可以使用它。

并添加此方法:

//[self addSkipBackupAttributeToItemAtURL:[NSURL fileURLWithPath:[AppDelegate applicationDocumentsDirectory]]];

    //[self addSkipBackupAttributeToItemAtURL:[NSURL fileURLWithPath:[AppDelegate applicationLibraryDirectory]]];

    //[self addSkipBackupAttributeToItemAtURL:[NSURL fileURLWithPath:[AppDelegate applicationTemporaryDirectory]]];

    [self addSkipBackupAttributeToItemAtURL:[NSURL fileURLWithPath:[AppDelegate applicationSupportDirectory]]];