Quote:
Originally Posted by antifreeze
i want to use a sqlite file just read-only. but when i build and run my project, my app create a new db file even there my file already prepared.
so, i explored iphone simulator directory and i saw that my app didn't copy my prepared sqlite file to 'myapp\document'.
what should i do?
|
in your appDelegate .m file:
Code:
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
//**************** Check if Database is on Users Phone. If not move a copy over ********************
databaseName = @"putyourDBNameHere.sqlite";
// Get the path to the documents directory and append the databaseName
NSArray *documentPaths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *documentsDir = [documentPaths objectAtIndex:0];
databasePath = [documentsDir stringByAppendingPathComponent:databaseName];
BOOL success;
// Create a FileManager object, we will use this to check the status of the database and to copy it over if required
NSFileManager *fileManager = [NSFileManager defaultManager];
// Check if the database has already been created in the users filesystem
success = [fileManager fileExistsAtPath:databasePath];
// If the database already exists
if(success) {
NSLog(@"Database already exists.");
}
else {
// If not then proceed to copy the database from the application to the users filesystem
NSLog(@"Database does not exist. *** Moving one from mainBundle ***");
NSString *databasePathFromApp = [[[NSBundle mainBundle] resourcePath] stringByAppendingPathComponent:databaseName];
// Copy the database from the package to the users filesystem
[fileManager copyItemAtPath:databasePathFromApp toPath:databasePath error:nil];
}
[window addSubview:navigationController.view];
[window makeKeyAndVisible];
return YES;
}