核心数据和iOS数据存储指南

时间:2012-04-23 18:26:30

标签: core-data ios5 icloud

我们有一个使用Core Data的应用程序,而后备存储是一个SQLite数据库。

它包含关键数据(即它必须始终可脱机使用)。

它目前存储在Documents目录中,因此因iOS数据存储指南而被拒绝。

解决方案似乎是使用“不备份”标记来标记它。

但是,我没有看到任何关于此的指导方针。即我应该手动将此文件标记为“不备份”,还是应该启用一些核心数据选项?

2 个答案:

答案 0 :(得分:1)

你必须自己手动完成,这是指南

https://developer.apple.com/library/ios/ipad/#qa/qa1719/_index.html

答案 1 :(得分:0)

在iOS 5.1或更高版本中,最好使用新的NSURLIsExcludedFromBackupKeykCFURLIsExcludedFromBackupKey文件属性,而不是setxattr (iOS 5.0.1 compatible)

- (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;
}

有关详细信息,请参阅 "App Backup Best Practices" section of the iOS App Programming Guide

相关问题