0
私のアプリケーションがシミュレータ上で完璧に動作するようになりましたが、iPhoneにロードするとデータベースが登録されません。私は私の初期化とデータベースのコピーに何か問題があることを知っている。データベースは私が推測するアプリケーションバンドルに保存されていません。私が間違っていることについての指導をしたいと思います。SQLiteデータベースがiPhoneにコピーされない
データベース内のデータも編集する予定ですので、これを考慮してください。ここで
コードされています
- (void)applicationDidFinishLaunching:(UIApplication *)application {
// Use this section to bring in database and populate the array
dbPath = @"https://stackoverflow.com/users/jr/Documents/projectReference/reference.db";
FMDatabase *database = [FMDatabase databaseWithPath:dbPath];
[database open];
// Init the subjects Array
categories = [[NSMutableArray alloc] init];
subjects = [[NSMutableArray alloc] init];
quotes = [[NSMutableArray alloc] init];
quoteMap = [[NSMutableArray alloc] init];
[self copyDatabaseIfNeeded];
// Open the database from the users filessytem
NSLog(@"Going into the while loop for categories");
FMResultSet *result_categories = [database executeQuery:@"select distinct category from SUBJECT"];
}
- (void) copyDatabaseIfNeeded {
//Using NSFileManager we can perform many file system operations.
NSFileManager *fileManager = [NSFileManager defaultManager];
NSError *error;
NSString *newdbPath = [self dbPath];
BOOL success = [fileManager fileExistsAtPath:newdbPath];
if(!success) {
NSString *defaultDBPath = [[[NSBundle mainBundle] resourcePath] stringByAppendingPathComponent:@"reference.db"];
success = [fileManager copyItemAtPath:defaultDBPath toPath:newdbPath error:&error];
NSLog(@"Database file copied from bundle to %@", newdbPath);
if (!success)
NSAssert1(0, @"Failed to create writable database file with message '%@'.", [error localizedDescription]);
} else {
NSLog(@"Database file found at path %@", newdbPath);
}
}
ありがとう、これで解決しました。 – jroyce