- (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;
}
foundInBundle によると、CoordinatesDatabase.sql はアプリケーション バンドルに存在します。「copySuccess = [fileManager copyItemAtPath: srcPath toPath: userPath error: &error];」ができないのはなぜですか? 成功する?
それが生成するエラーは、「操作を完了できませんでした。Cocoa エラー 4」のようなものです。私のグーグルによると、Cocoa Code Error 4 は NSFileNoSuchFileError を意味しますが、アプリバンドルに CoordinatesDatabase.sql があることは確かです。
または、CoordintesDatabase.sql がアプリ バンドルに存在するというのは間違っていますか?