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

  • Home
  • SEARCH
  • 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 6210069
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T06:05:44+00:00 2026-05-24T06:05:44+00:00

I have a core data app that I am using with a sql lite

  • 0

I have a core data app that I am using with a sql lite db. I’ve populated it in my simulator and now I’d like to send it with the app, but whenever I install it on the ipad, the db is blank!

I’ve added the populated db to the project (from the simulator folder) and I have the following in the delegate:

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
[window addSubview:splitViewController.view];
[window makeKeyAndVisible];

NSString *Path = [[NSBundle mainBundle] bundlePath];
NSString *DataPath = [Path stringByAppendingPathComponent:@"data.plist"];

NSDictionary *tempDict = [[NSDictionary alloc] initWithContentsOfFile:DataPath];
self.data = tempDict;
[tempDict release];

// Override point for customization after application launch.
// Add the split view controller's view to the window and display.
[self createEditableCopyOfDatabaseIfNeeded];


NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
NSMutableDictionary *appDefaults = [NSMutableDictionary dictionaryWithObject:@"NO" forKey:@"enableRotation"];
[appDefaults setObject:@"0" forKey:@"orientation"];
[appDefaults setObject:@"100" forKey:@"repID"];
[appDefaults setObject:@"Atlanta Dental" forKey:@"RepName"];
[defaults registerDefaults:appDefaults];

//self.window.rootViewController = self.splitViewController;
return YES;
}

-(void)createEditableCopyOfDatabaseIfNeeded
{
// Testing for existence
BOOL success;
NSFileManager *fileManager = [NSFileManager defaultManager];
NSError *error;
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory,
                                                     NSUserDomainMask, YES);
NSString *documentsDirectory = [paths objectAtIndex:0];
NSString *writableDBPath = [documentsDirectory stringByAppendingPathComponent:DATABASE_NAME];

success = [fileManager fileExistsAtPath:writableDBPath];
if (success)
    return;

// The writable database does not exist, so copy the default to
// the appropriate location.
NSString *defaultDBPath = [[[NSBundle mainBundle] resourcePath]
                           stringByAppendingPathComponent:DATABASE_NAME];
success = [fileManager copyItemAtPath:defaultDBPath
                               toPath:writableDBPath
                                error:&error];
if(!success)
{
    NSFileManager *fileManager = [NSFileManager defaultManager];
    // If the expected store doesn't exist, copy the default store.
    //if ( ! [fileManager fileExistsAtPath:storePath])
    //{
        NSString *defaultStorePath = [[NSBundle mainBundle] pathForResource:@"D4" ofType:@"sqlite"];
        if ( defaultStorePath )
        {
            [fileManager copyItemAtPath:defaultStorePath toPath:writableDBPath error:NULL];
        }
    //}
    //NSAssert1(0,@"Failed to create writable database file with Message : '%@'.",
    //        [error localizedDescription]);
}
}


 - (NSPersistentStoreCoordinator *)persistentStoreCoordinator
{
if (persistentStoreCoordinator != nil)
{
    return persistentStoreCoordinator;
}

NSURL *storeURL = [[self applicationDocumentsDirectory] URLByAppendingPathComponent:DATABASE_NAME];

NSError *error = nil;
persistentStoreCoordinator = [[NSPersistentStoreCoordinator alloc] initWithManagedObjectModel:[self managedObjectModel]];
NSDictionary *options = [NSDictionary dictionaryWithObjectsAndKeys:
                         [NSNumber numberWithBool:YES], NSMigratePersistentStoresAutomaticallyOption, 
                         [NSNumber numberWithBool:YES], NSInferMappingModelAutomaticallyOption, nil];

if (![persistentStoreCoordinator addPersistentStoreWithType:NSSQLiteStoreType configuration:nil URL:storeURL options:options error:&error])
{
    NSLog(@"Unresolved error %@, %@", error, [error userInfo]);
    abort();
}    

return persistentStoreCoordinator;
}

Any ideas?

EDITED TO ADD:

When I explore the iPad with iphone explorer, I can see the original populated DB in the app path, so it is getting copied. That means I must have the above wrong. . .

right?

  • 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-24T06:05:45+00:00Added an answer on May 24, 2026 at 6:05 am

    Since the store is always blank, that means the persistent store coordinator does not find an existing store at the URL you provide so it creates a new empty store. The most likely explanation for the missing store is that it is not being copied to where you think it is being copied.

    You never use the same method twice to get the path to either the default file in the app bundle or the path to the readwrite file in the documents. Each time you create a path, you use different code. This makes it possible that you are generating different paths at different points in the code. Pick one method for generating each path and reuse as necessary.

    I would suggest logging all the paths and URLs to confirm they all point where you think they do. I would also recommend trapping errors for file manage operations. You can get errors even if the bool return is YES.

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

Sidebar

Related Questions

I'm using core data in my app. I have two entities that are related:
I have developed my app using core data. It works fine in the simulator.
I have a core data app that is using the sectionNameKeyPath group.name with the
I have an iPhone app using Core Data, but I can't seem to figure
I was just wondering, I have an app that relies on Core Data for
I have a Core Data app that will end up being an iPhone/iPad universal
I have a Core Data app that works to add or remove one of
I have a Core Data-based iPhone app with a pre-populated read-only database. What protection
Im using a Core Data model for my iPhone app. I have been looking
I'm currently developing an app that uses Core Data. I'm using two stores/configurations, one

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.