gpt4 book ai didi

ios - Objective-C:复制和删除文件(文件管理器)

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

我正在使用 FMDatabase 处理 sqlite 数据库应用程序。

我想更新位于主包中的数据库表

NSString *defaultDBPath = [[[NSBundle mainBundle] resourcePath] stringByAppendingPathComponent:db_name];

数据位于文档目录中的数据库中

NSArray  *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *docsPath = [paths objectAtIndex:0];
NSString *db_Path = [docsPath stringByAppendingPathComponent:db_name];

我多次尝试在“默认”数据库上执行更新查询,但它说它已被锁定。所以我考虑在文档目录中使用名称 db_name_cp 来处理它并对其进行处理。

NSString *cpPath = [documentsDirectory stringByAppendingPathComponent:@"db_name_cp.sqlite"];
success = [fileManager fileExistsAtPath:cpPath];
if (success){
//remove the existing one
[fileManager removeItemAtPath:cpPath error:&error];
}
//create the copy of the "main bundle" database
[fileManager copyItemAtPath:default_database.dbPath toPath:cpPath error:&error];

然后我尝试对复制的数据库执行 UPDATE,但如果我对它执行 SELECT,它不会更新,如果我在 phpMyAdmin 或 SQLiteManager 上运行查询,它会更新记录。

有什么想法吗?也许我在设备目录上处理它们是错误的。

非常感谢

最佳答案

您不能更改应用程序中的任何内容,这显然包括应用程序的 mainBundle,它是只读的且已签名。

Documents 目录很好,它是要使用的正确目录。

如果需要合并则合并到Documents目录下的DB中。或者在第一次启动时将捆绑数据库复制到 Documents 目录,然后合并到其中。

关于ios - Objective-C:复制和删除文件(文件管理器),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23833509/

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