- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
// Override point for customization after application launch.
if ([[UIDevice currentDevice] userInterfaceIdiom] == UIUserInterfaceIdiomPad) {
UISplitViewController *splitViewController = (UISplitViewController *)self.window.rootViewController;
UINavigationController *navigationController = [splitViewController.viewControllers lastObject];
splitViewController.delegate = (id)navigationController.topViewController;
}
NSString *dbFilename = @"CoordinatesDatabase.sql";
NSString *userPath = [[CoordinatesAppDelegate applicationDocumentsDirectory] stringByAppendingPathComponent: dbFilename];
NSString *srcPath = [[[NSBundle mainBundle] resourcePath] stringByAppendingPathComponent: dbFilename];
NSLog(@"userPath %@", userPath);
NSLog(@"srcPath %@", srcPath);
NSFileManager *fileManager = [NSFileManager defaultManager];
BOOL foundInBundle = [fileManager fileExistsAtPath: srcPath];
BOOL foundInUserPath = [fileManager fileExistsAtPath: userPath];
BOOL copySuccess = FALSE;
NSError *error;
if(foundInBundle)
{
if(!foundInUserPath)
{
NSLog(@"don't have copy, copy one");
copySuccess = [fileManager copyItemAtPath: srcPath toPath: userPath error: &error];
}
if(!copySuccess)
{
NSLog(@"Failed with message: %@'.", [error localizedDescription]);
}
}
else
{
NSLog(@"Some error");
}
return YES;
}
According to foundInBundle, the CoordinatesDatabase.sql exists in the application bundle. Why can't the "copySuccess = [fileManager copyItemAtPath: srcPath toPath: userPath error: &error];" be successful?
The error it produces is something like "Operation couldn't be completed. Cocoa Error 4". According to my googling, Cocoa Code Error 4 means NSFileNoSuchFileError but I'm really sure that the CoordinatesDatabase.sql is there in the app bundle.
Or am I wrong that CoordintesDatabase.sql does exist in the app bundle?