iPhone没有';t创建sqlite数据库文件

iPhone没有';t创建sqlite数据库文件,iphone,sqlite,Iphone,Sqlite,我在创建数据库文件时遇到问题。我正在使用这个函数: - (void)createEditableCopyOfDatabaseIfNeeded { // Testing for existence BOOL success; NSFileManager *fileManager = [NSFileManager defaultManager]; NSError *error; NSArray *paths = NSSearchPathForDirectori

我在创建数据库文件时遇到问题。我正在使用这个函数:

- (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];

    NSLog(@"%@", writableDBPath);

    success = [fileManager fileExistsAtPath:writableDBPath];
    if (success) {
        NSLog(@"The file was here");
        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:&error];
    NSLog(@"New file created");

    if(!success)
    {
        NSAssert1(0,@"Failed to create writable database file with Message : '%@'.",
                  [error localizedDescription]);
    }
}
执行此操作总是会生成日志“newfilecreated”,但如果我将查找器指向db路径,我会发现一个空文件夹:该文件未创建

你认为有什么问题

(我有另一个应用程序使用相同的功能,效果很好!)

更新:


如果我使用finder的“转到文件夹”功能并粘贴到
defaultDBPath
,它会告诉我我没有访问文件夹所需的特权无法立即发现您的常规代码有问题,但请注意
NSLog(@“新建文件”)将始终出现,因为您没有检查
成功
。与文件的测试一样,您需要检查
成功

if (success)
    NSLog(@"New file created");

然后,您将至少正确地测试它是否认为创建了文件。如果没有,请仔细检查您的
defaultDBPath
writeabledbpath
变量。

好的,我解决了它。。。我真蠢

我只是简单地将数据库名称设置为“villaggio.
db
”,而我真正的数据库名称为“villaggio.
sqlite


=D

数据库_NAME的字符串值是多少?#定义数据库_NAME@“villaggio.db”