适用于iPhone的appite中的SQLite数据库更新

时间:2011-07-14 10:49:53

标签: iphone objective-c sqlite

我看到有很多类似的问题,但通过它们找不到我的问题的答案。

有一个使用sqlite数据库的iPhone应用程序。需要更新应用程序,一切都很顺利。 当我在iPhone上安装应用程序时,它工作正常,但是当我在某些设备上更新已经安装的应用程序时,它将我与旧数据库混合在一起,直到我删除并再次安装应用程序才能正常运行。

我在设备上检查数据的代码是:

   /*
 This method checks is rawdata has been copied to Documents directory. 
 If not, copies and returns YES, to start conversion.
 Else, if already copied, reply NO.
*/
- (void) checkImportIsNeededFrom: (NSString*) bundledRawFilePath toDestination:(NSString*) documentSavedRawFilePath 
{
    NSLog(@"Checking rawdata file into Documents folder..");
    if ([[NSFileManager defaultManager] fileExistsAtPath:documentSavedRawFilePath]) {
        importIsNeeded = NO; // SET YES TO FORCE IMPORT ON EACH STARTUP
        NSLog(@"copy already existing in %@", documentSavedRawFilePath);
    } else {
        [[NSFileManager defaultManager] copyItemAtPath:bundledRawFilePath toPath:documentSavedRawFilePath error:NULL];
        importIsNeeded = YES;
        NSLog(@"copy %@ to %@ done...", bundledRawFilePath, documentSavedRawFilePath);
    }
}

- (BOOL) importIsNeeded {
    return importIsNeeded;
}

所以我只需要帮助删除设备上的旧设备并将其替换为新设备。有没有简单的解决方案。

感谢。

1 个答案:

答案 0 :(得分:0)

您的代码只会检查设备上是否已存在数据库,但它不会检查它是新的还是旧的。

升级应用时,之前的数据库仍然存在,因此importIsNeeded将设置为NO。我假设应用程序然后尝试使用数据库,就好像它是新数据库并崩溃一样?

您需要检查该位置存在哪个数据库,而不仅仅是存在一个