开发者

SQLite database update in app for iPhone

I see there is a lot of similar questions but passing through them not find answer to my question.

Have an app for iPhone that uses sqlite database. Need to update app and everything went good. When I install app on iPhone it works fine, but when I update already installed app on some device it mixed me with old database and not functioning until i delete and again install app.

My code for checking data on device is:

   /*
 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 import开发者_如何学GoIsNeeded;
}

So I just need some help with deleting old one on device and replace it with new one. Is there any easy solution.

Thanks.


You're code only checks that there is a daabase already on the device, it doesn't check to see if it's the new or the old one.

When an app is upgraded, the previous database will still be there so importIsNeeded will be set to NO. I assume that the app then tries to use the database as if it were the new one and crashes?

You need to check which database is present at that location, not just if one exists at all.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜