微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

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

在模拟器上运行没有问题;
在真机上报如下错误
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

原文地址:https://www.jb51.cc/sqlite/201741.html

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。

相关推荐