加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

使用sqlite时遇到的错误 read-only

发布时间:2020-12-12 20:25:53 所属栏目:百科 来源:网络整理
导读:在模拟器上运行没有问题; 在真机上报如下错误: Attempt to add read-only file at path file://localhost/var/mobile/Applications/A80208B7-36C8-4CD0-94D9-E3EC57BDA4D6/BookingMeals.app/ShopCar.sqlite read/write. Adding it read-only instead. This
在模拟器上运行没有问题;
在真机上报如下错误:
Attempt to add read-only file at path file://localhost/var/mobile/Applications/A80208B7-36C8-4CD0-94D9-E3EC57BDA4D6/BookingMeals.app/ShopCar.sqlite read/write. Adding it read-only instead. This will be a hard error in the future; you must specify the NSReadOnlyPersistentStoreOption.

问题已经解决,多谢各位,特别是3楼。
resources中的文件全为只读文件,因此需要将sqlite文件拷贝到document目录中使用。

代码如下:
NSString *path =[[NSBundle mainBundle] pathForResource:@"数据库文件名" ofType:nil];
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSCachesDirectory,NSUserDomainMask,YES);
NSString *documentsDirectory = [paths objectAtIndex:0];
NSString *writableDBPath = [documentsDirectory stringByAppendingPathComponent:@"ShopCar.sqlite"];
[[NSFileManager defaultManager]copyItemAtPath:path toPath:writableDBPath error:nil];

NSURL *url = [NSURL fileURLWithPath:writableDBPath];


http://www.cocoachina.com/bbs/simple/?t113925.html

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读