Note that there are some explanatory texts on larger screens.

plurals
  1. POpopulated sql lite db is blank when transferred to ipad
    primarykey
    data
    text
    <p>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, <em>but</em> whenever I install it on the ipad, the db is blank!</p> <p>I've added the populated db to the project (from the simulator folder) and I have the following in the delegate:</p> <pre><code>- (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:&amp;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:&amp;error]) { NSLog(@"Unresolved error %@, %@", error, [error userInfo]); abort(); } return persistentStoreCoordinator; } </code></pre> <p>Any ideas?</p> <p>EDITED TO ADD:</p> <p>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. . . </p> <p>right?</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload