Iphone 未将SQLite文件添加到捆绑资源

Iphone 未将SQLite文件添加到捆绑资源,iphone,xcode,bundle,Iphone,Xcode,Bundle,我有一个文件event\u setup.sqlite,它放在我的应用程序中,并复制到构建阶段的Copy Bundle Resources部分 当涉及到将此文件从资源复制到文档目录时,我的应用程序说找不到该文件。我正在使用以下代码从资源中复制该文件,并告诉我该文件不存在: - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions{

我有一个文件
event\u setup.sqlite
,它放在我的应用程序中,并复制到构建阶段的
Copy Bundle Resources
部分

当涉及到将此文件从资源复制到文档目录时,我的应用程序说找不到该文件。我正在使用以下代码从资源中复制该文件,并告诉我该文件不存在:

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions{
    [self checkAndCreateDatabase: @"event_setup.sqlite"];
    return YES;
}

-(void)checkAndCreateDatabase:(NSString *)name{
    /*----Get the path to the Database----*/
    NSArray *documentPaths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
    NSString *documentsDir = [documentPaths objectAtIndex:0];
    NSString *databasePath = [documentsDir stringByAppendingPathComponent:name];

    BOOL success;
    NSFileManager *fileManager = [NSFileManager defaultManager];

    success = [fileManager fileExistsAtPath:databasePath];

    if(success){
        NSLog(@"Database already exists");
        return;
    }
    else{
        NSLog(@"Database does not exist");
        NSString *databasePathFromApp = [[[NSBundle mainBundle] resourcePath] stringByAppendingPathComponent:name];

        bool test = [fileManager fileExistsAtPath:databasePathFromApp];
        if(test){
            NSLog(@"file does exist in resources: %@", databasePathFromApp);
        }
        else{
            NSLog(@"file does not exist in resources: %@", databasePathFromApp);
        }

        [fileManager copyItemAtPath:databasePathFromApp toPath:databasePath error:nil];
    }
}
运行此代码时,我会在日志中看到以下内容:

file does not exist in resources: /Users/samrowley/Library/Application Support/iPhone Simulator/6.1/Applications/583D4293-3AD5-45FB-B502-9919F51FDB7B/Test.app/event_setup.sqlite
我尝试过清理应用程序,重新启动Xcode,删除文件并将其重新压缩到Xcode中,但似乎没有任何效果

编辑:

终端命令的输出:

-rw-r--r--   1 samrowley  staff    2797 11 Feb 10:51 divider.png
-rw-r--r--   1 samrowley  staff    2803 11 Feb 10:51 divider@2x.png
drwxr-xr-x   3 samrowley  staff     102 11 Feb 10:51 en.lproj
-rw-r--r--   1 samrowley  staff    2937 11 Feb 10:51 header.png
-rw-r--r--   1 samrowley  staff    3205 11 Feb 10:51 header@2x.png

这个问题的答案是该文件未正确添加到目标。要将其添加到目标,您需要进入文件检查器,在目标检查器下,必须检查该文件的应用程序名称。

很高兴我在@SamRowley找到了您的答案,因为它让我烦恼了一段时间。在我创建的其他每个应用程序中,sqlite数据库都出现在应用程序包中,没有问题,所以这次我一定是以不同的方式添加了它。我包括了这张Xcode 7.3.1的图片,因为名称似乎有了轻微的变化。如图所示,您需要检查
目标成员资格
,否则文件将不会复制到应用程序包中


发布此
终端.app
命令的输出:
ls-lR/Users/samrowley/Library/Application Support/iPhone Simulator/6.1/Applications/583D4293-3AD5-45FB-B502-9919F51FDB7B/Test.app
。添加了问题的输出。这很奇怪,因为我在应用程序中有另一个数据库,它的访问方式完全相同,但那一个可以工作。好吧,让我们用一些引号重试:
ls-lR'/Users/samrowley/Library/Application Support/iPhone Simulator/6.1/Applications/583D4293-3AD5-45FB-B502-9919F51FDB7B/Test.app'
该文件不包含在该命令的输出中。将部分输出添加到编辑中。好的,那么沃森,我们从中得出什么结论?我想你最近提出的另一个问题的答案是相同的:我想是这样。不过,我现在已经找到了解决这个问题的办法。谢谢你的时间和帮助,没问题。我很乐意帮忙。