如何设置默认领域路径到App Groups目录 [英] How to set default realm path to App Groups directory

查看:537
本文介绍了如何设置默认领域路径到App Groups目录的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我尝试将默认的Realm路径设置为App Groups目录。

I am trying to set the default Realm path to App Groups directory.

let directory: NSURL = NSFileManager.defaultManager().containerURLForSecurityApplicationGroupIdentifier("groups.prasanna.appName")!  
RLMRealm.setDefaultRealmPath(directory.absoluteString!)  
println(RLMRealm.defaultRealmPath())  


$ b b

应用崩溃时出现以下错误

The app crashes with the following error


由于未捕获异常RLMException而终止应用,原因: :不允许操作'

Terminating app due to uncaught exception 'RLMException', reason: 'open() failed: Operation not permitted'

如何解决此问题?

推荐答案

您设置的默认领域路径是您的容器目录。您必须为此添加一个文件名:

the default realm path you're setting is your container directory. You'll have to append a file name for this to work:

let directory: NSURL = NSFileManager.defaultManager().containerURLForSecurityApplicationGroupIdentifier("groups.prasanna.appName")!
let realmPath = directory.path!.stringByAppendingPathComponent("db.realm")
RLMRealm.setDefaultRealmPath(realmPath)
println(RLMRealm.defaultRealmPath()) // should be realmPath

这篇关于如何设置默认领域路径到App Groups目录的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆