まず、data_items.sqlite という名前を使用してデータベースを作成し、.sqlite 拡張子を削除します。次に、このデータベースを xCode の Resources ディレクトリにドラッグし、次の手順に従います。
ファイル ボックスを追加するためのオプションを選択すると、チェック ボックスが表示され、[アイテムを宛先グループのフォルダーにコピーする (必要な場合)] と表示され、終了します。
リソースディレクトリのサブリストとしてデータベースファイルが表示されます
申し訳ありませんが、ここに画像を投稿するのに十分な評判がありません
リンクをたどって、このデータベースファイルを場所にコピーします
アプリケーションがiOSで起動されたときにsqliteデータベースをコピーする方法は?
AppDelegate.m の最後の行で @end の前に次のコードを使用しました
- (void) copyDatabaseIfNeeded{
NSFileManager *fileManager = [NSFileManager defaultManager];
NSError *error;
_dbPath = [self getDBPath];
BOOL success = [fileManager fileExistsAtPath:_dbPath];
if(!success){
NSString *defaultDBPath = [[[NSBundle mainBundle] resourcePath] stringByAppendingPathComponent:@"data_items"];
success = [fileManager copyItemAtPath:defaultDBPath toPath:_dbPath error:&error];
if (!success)
NSAssert1(0, @"Failed to create writable database file with message '%@'.", [error localizedDescription]);
}}
/********* Database Path *********/
- (NSString *) getDBPath
{
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory,NSUserDomainMask,YES);
NSString *documentsDir = [paths objectAtIndex:0];
return [documentsDir stringByAppendingPathComponent:@"data_items"];
}
そして行をコピーします
[self copyDatabaseIfNeeded];
コードの後に
- (BOOL)application:(UIApplication*)application didFinishLaunchingWithOptions:(NSDictionary*)launchOptions
{
CGRect screenBounds = [[UIScreen mainScreen] bounds];
それでおしまい。コードを使用する
function onDeviceReady() {
var db = window.sqlitePlugin.openDatabase("data_items", "1.0", "data_items", 200000);
...
}
コピーした場所からデータベースを直接編集することもできます。次のリンクを使用
iPhone Simulator のデータはどこに保存されますか?