1

我有一个需要由我的 iOS 应用程序读取的 sqlite 文件,但是 xcode 在将它复制到应用程序中时给了我一个错误...我将 sql 文件放在我项目的“支持文件”文件夹中。这是代码:

-(NSString *)filePath {
    NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory,
                                                         NSUserDomainMask,
                                                         YES);

    return [[paths objectAtIndex:0] stringByAppendingPathComponent:
                                                         @"LocationsApp.sql"];
}

-(void)createEditableCopyOfDatabaseIfNeeded {
    BOOL success;
    NSFileManager *fileManager = [NSFileManager defaultManager];
    NSError *error;
    NSString *writableDBPath = [self filePath];
    success = [fileManager fileExistsAtPath:writableDBPath];

    if (success)
    {
        return;
    }

    NSString *defaultDBPath = [[[NSBundle mainBundle] resourcePath] stringByAppendingPathComponent:@"LocationsApp.sql"];
    success = [fileManager copyItemAtPath:defaultDBPath toPath:writableDBPath error:&error];
    if (!success)
    {
        NSAssert1(0, @"Failed to create writable database file with message '%@'.", [error localizedDescription]);
    }
}

这是错误:

2013-10-03 13:21:35.282 LaGuida[1872:60b] * 断言失败 -[FirstViewController createEditableCopyOfDatabaseIfNeeded], /Volumes/Lavoro/AppleDev/LaGuida/LaGuida/FirstViewController.m:87 2013-10-03 13:21 :35.284 拉圭达[1872:60b]由于未捕获的异常“NSInternalInconsistencyException”而终止应用程序,原因:“无法创建带有消息的可写数据库文件”操作无法完成。(可可错误 260。)'。' * * First throw call stack: (0x2e4f8e8b 0x387f36c7 0x2e4f8d5d 0x2eea123f 0x6b201 0x6abad 0x30c8297d 0x30c828f9 0x30daa7cf 0x30daa663 0x30daa56f 0x30c8fed5 0x30dadeb5 0x30dad333 0x30c98907 0x30c8a5a7 0x30c89d5f 0x30c89bd3 0x30c89701 0x30c86cc5 0x30cf219d 0x30ceef75 0x30ce94b9 0x30c83be7 0x30c82edd 0x30ce8ca1 0x3316476d 0x33164357 0x2e4c377f 0x2e4c371b 0x2e4c1ee7 0x2e42c541 0x2e42c323 0x30ce7f43 0x30ce31e5 0x6bbdd 0x38cecab7) libc++abi .dylib:以 NSException 类型的未捕获异常终止

4

1 回答 1

0

更正您的 DBName

LocationsApp.sql to LocationsApp.sqlite

或者你的 DBName 是什么

于 2013-10-03T12:00:54.023 回答