使用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

相关文章

SQLite架构简单,又有Json计算能力,有时会承担Json文件/RES...
使用Python操作内置数据库SQLite以及MySQL数据库。
破解微信数据库密码,用python导出微信聊天记录
(Unity)SQLite 是一个软件库,实现了自给自足的、无服务器...
安卓开发,利用SQLite实现登陆注册功能