ios - 主包中的 Realm realmWithPath 方法在 iOS 上崩溃

标签 ios realm

我没有在应用程序的文档目录中使用 *.realm 文件。我在主包目录中使用它。

当我调用它时:

NSString *path = [[NSBundle mainBundle] pathForResource:@"example" ofType:@"realm"];
RLMRealm *realm  = [RLMRealm realmWithPath:path];

它崩溃并记录:

由于未捕获的异常“RLMException”而终止应用程序,原因:“open() 失败:不允许操作”

最佳答案

Realm 文件必须位于您具有写入权限的目录中,以防您希望能够更新任何数据。 如果您只打算使用您的应用程序分发预设数据库并以只读方式访问它,则必须以只读方式打开它 [RLMRealm realmWithPath:readOnly:error:] .

关于ios - 主包中的 Realm realmWithPath 方法在 iOS 上崩溃,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26320073/

相关文章:

ios - 在iOS Swift中从设备获取图像的URL路径

java - 安全标志 fstack-protector Realm library Android

swift - 在设备上运行时无法连接到 Realm 对象服务器

swift - Realm/swift : compilation error: Missing argument for parameter 'forPrimaryKey' in call

ios - 实例化可选 Realm 对象的线程安全方式

ios - 如何使用 tableView 和 Realm 创建和保存一对多关系(父子关系)

objective-c - iOS 解析Webservice数据

iphone - 禁止在 subview 上接收来自父 View 的触摸

ios - RubyMotion Firebase (motion-firebase) 如何查询单个键

ios - 为什么我的指示器在加载网页 View 时不起作用?