0

私はコアデータを使用して最初のアプリケーションに取り組んでいます。すべてが完璧に機能します。デバイスでアプリをデバッグし (デバイスにまだインストールされていない状態で)、アプリを終了し、sqlite dbase を手動で変更してからアプリを再度デバッグすると、古いバージョンのデータベースを使用しているように見えます。2 つの sqlite ファイルが同じ名前の場合、そこにあるものを単に置き換えるように指示する方法はありますか?

これが私のコードのスニペットです:

NSString *storePath = [[self applicationDocumentsDirectory] stringByAppendingPathComponent: @"mydata.sqlite"];

    /*
     Set up the store.
     For the sake of illustration, provide a pre-populated default store.
     */
     NSFileManager *fileManager = [NSFileManager defaultManager];
     // If the expected store doesn't exist, copy the default store.
     if (![fileManager fileExistsAtPath:storePath]) {
        NSLog(@"copying default from sqlite");
        NSString *defaultStorePath = [[NSBundle mainBundle] pathForResource:@"mydata" ofType:@"sqlite"];
         if (defaultStorePath) {
            [fileManager copyItemAtPath:defaultStorePath toPath:storePath error:NULL];
         }
     }


    NSURL *storeUrl = [NSURL fileURLWithPath:storePath];

ご覧のとおり、最初にデータベースが見つからない場合は、アプリから sqlite ファイルを読み込みます。sqlite ファイルの名前を変更するか、設定を使用する以外に、何かあれば何でもフラッシュして、最初からやり直す方法はありますか?

ユーザーがアプリを購入していて、更新をリリースしても、古いバージョンのデータベースからのデータがまだ表示されているのではないかと心配しています。

ありがとう、ハウィー

4

1 に答える 1

0

古いデータベースを削除し、最初に行ったのと同じ方法で、更新に同梱されているデータベースをコピーできます。

NSString *storePath = [[self applicationDocumentsDirectory] stringByAppendingPathComponent:@"Test.sqlite"];
NSURL *storeURL = [NSURL fileURLWithPath:storePath];
[[NSFileManager defaultManager] removeItemAtURL:storeURL error:nil]

データベースが古くなっているかどうかを判断する方法が必要なだけです。

于 2010-08-17T11:39:41.273 に答える