gpt4 book ai didi

ios - 从应用程序包复制文件时出错

转载 作者:行者123 更新时间:2023-11-29 02:43:50 25 4
gpt4 key购买 nike

我使用了 FireFox 附加 SQLite 管理器,创建了一个数据库,并将其作为“DB.sqlite”保存到我的桌面。我将该文件复制到我的项目支持文件中。但是当我运行应用程序时,我立即收到错误

"Assertion failure in -[AppDelegate copyDatabaseIfNeeded], /Users/Mac/Desktop/Note/Note/AppDelegate.m:32 2014-08-19 23:38:02.830 Note[28309:60b] Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'Failed to create writable database file with message 'The operation couldn’t be completed. (Cocoa error 4.)'.' First throw call stack: "...

这里是出现错误的App Delegate Code

-(void) copyDatabaseIfNeeded
{
NSFileManager *fileManager = [NSFileManager defaultManager];
NSError *error;
NSString *dbPath = [self getDBPath];
BOOL success = [fileManager fileExistsAtPath:dbPath];

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

}
}

我是 Sqlite 的新手,所以我可能没有在 FireFox Sqlite 管理器中正确创建数据库,或者我没有“正确”复制 .sqlite 文件? (我确实检查了 sqlite 中的目标成员资格,它正确地选择了我的项目。此外,.sqlite 文件名完全匹配。)

最佳答案

在 iOS 中,您不能在应用程序包中写入文件。整个包是只读的。 您应该在 NSDocumentDirectory 中创建数据库(sqlite 文件)以便对其进行处理。

请访问以下网站获取教程: http://objectivecwithsuraj.blogspot.in/2012/10/database-implementation-using-sqlite-in.html

示例代码: https://github.com/surajwebo/SQLite-Demonstration-

关于ios - 从应用程序包复制文件时出错,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25398397/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com