【发布时间】:2013-10-03 11:52:55
【问题描述】:
我有一个我的 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 LaGuida[1872:60b] 由于未捕获的异常“NSInternalInconsistencyException”而终止应用程序,原因:“无法创建带有消息的可写数据库文件”操作无法完成。 (可可错误 260。)'。' ** 首先抛出调用堆栈: (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 类型的未捕获异常终止
【问题讨论】:
-
Cocoa 错误 260:没有这样的文件,看起来您尝试从包中复制的文件不存在。尝试记录
defaultDBPath和writableDBPath -
已解决...扩展名错误,谢谢
标签: ios objective-c sqlite