- (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];” 成功的?
它产生的错误类似于“无法完成操作。可可错误 4”。根据我的谷歌搜索,Cocoa Code Error 4 表示 NSFileNoSuchFileError 但我很确定 CoordinatesDatabase.sql 存在于应用程序包中。
或者我错了 CoordintesDatabase.sql 确实存在于应用程序包中?