Я дошел до того, что мое приложение отлично работает на симуляторе, но когда я загружаю его на свой iPhone, база данных не регистрируется.Я знаю, что у меня что-то не так с моей инициализацией и копированием БД.Думаю, база данных не сохраняется в комплекте приложений.Я хотел бы получить указание о том, что я делаю неправильно.
Я планирую также редактировать данные в базе данных, поэтому хотел бы, чтобы это учитывалось.
Вот код:
- (void)applicationDidFinishLaunching:(UIApplication *)application {
// Use this section to bring in database and populate the array
dbPath = @"/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);
}
}