我正在尝试将默认 Realm 路径设置为 App Groups 目录。
let directory: NSURL = NSFileManager.defaultManager().containerURLForSecurityApplicationGroupIdentifier("groups.prasanna.appName")!
RLMRealm.setDefaultRealmPath(directory.absoluteString!)
println(RLMRealm.defaultRealmPath())
应用程序崩溃并出现以下错误
Terminating app due to uncaught exception 'RLMException', reason: 'open() failed: Operation not permitted'
我该如何解决这个问题?
最佳答案
您设置的默认 Realm 路径是您的容器目录。你必须附加一个文件名才能工作:
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
关于cocoa - 如何将默认 Realm 路径设置为 App Groups 目录,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27355557/