我有一个基于核心数据的应用程序,使用Dropbox备份和还原数据。我的备份方法很简单,我将用户的.sqlite文件复制到Dropbox上。目前,我的备份和还原功能都正常运行。但是我的问题出现在.sqlite文件本身。看起来这个文件不完整。我向应用程序中输入了大约125条记录并进行了备份。虽然备份出现在我的Dropbox中,但当我使用.sqlite浏览器工具查看内容时,我只能看到117条之前的记录。我尝试更新第一条记录,再次观察.sqlite文件,但仍然没有变化。更奇怪的是,应用程序似乎已经记录了所有的更改。当我添加新纪录或更新现有记录并重新启动应用程序时,新添加的数据似乎有保存下来。但是这些新添加的数据在我的.sqlite文件中却找不到。我正在使用以下代码进行备份:
AppDelegate *appDelegate = [[UIApplication sharedApplication] delegate];
NSString *filePath = [[[appDelegate applicationDocumentsDirectory] path] stringByAppendingPathComponent:@"MyApp.sqlite"];
if (account) {
if ([filesystem isShutDown]) {
filesystem = [[DBFilesystem alloc] initWithAccount:account];
[DBFilesystem setSharedFilesystem:filesystem];
}
DBPath *newPath = [[DBPath root] childPath:[NSString stringWithFormat:@"Backup - %@.sqlite", [NSDate date]]];
DBFile *file = [[DBFilesystem sharedFilesystem] createFile:newPath error:nil];
[file writeContentsOfFile:filePath shouldSteal:NO error:nil];
[filesystem shutDown];
}
我也从模拟器文件夹中复制了.sqlite文件,并尝试在.sqlite浏览器中查看它。它仍然表现出相同的行为。有什么原因会发生这种情况吗?