Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7088607
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T07:49:17+00:00 2026-05-28T07:49:17+00:00

I got to a point where my application works perfectly on the simulator but

  • 0

I got to a point where my application works perfectly on the simulator but when I load it onto my iPhone the database does not register. I know I have something wrong with my initialization and copying of the db. The database is not saving to the app bundle I guess. I would like direction on what I am doing wrong.

I plan to edit the data in the database as well so would want this taken into consideration.

Here is the code:

- (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);

}
}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-28T07:49:18+00:00Added an answer on May 28, 2026 at 7:49 am

    your static dir @”/users/jr/Documents/projectReference/reference.db” to database is wrong in a iOS context.
    you should use relative path detection. if you store your DB at bundle and copy it with other resources, just use this one:

    NSString *path = [[NSBundle mainBundle] pathForResource:@"reference" ofType:@"db" inDirectory:@""];
    

    if you create DB at runtime and store it in documents, use this one:

    NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
    NSString *documentsDirectoryPath = [paths objectAtIndex:0];
    NSString *dbPath = [resourcePath stringByAppendingPathComponent:@"reference.db"]
    

    or just read about this here and here.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

It is quite possible that I may not have got the point, but I
I asked a question yesterday which got answers but didnt answer the main point.
I've a simple flash application that does counting on button click. I load it
We've got an EXE which works great for installing our application. However, we have
I'm at my wit's end. The Share Point guy got a brain tumor and
At some point Find All References feature got broken for a single solution that
Case in point : I've got a handle to a window (for instance, using
got a problem with dets:to_ets/2 Could somebody point me to an example online? Ive
I've got a question about floating point precision. As I understand it, ULP is
Please tell me if I got this wrong. Anchor point is like a movable

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.