How to set default realm path to App Groups directory

不羁的心 提交于 2019-12-06 11:12:43
jpsim

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

RLMRealm.setDefaultRealmPath() removed at 0.97 version, you should use this : Tim answer

var config = RLMRealmConfiguration.defaultConfiguration()
config.path = realmPath
RLMRealmConfiguration.setDefaultConfiguration(config)

It has changed again, now:

let configuration = RLMRealmConfiguration.default()
configuration.pathOnDisk = realmPath
RLMRealmConfiguration.setDefault(configuration)
Pramod Patil

In Xamarin, you can do somethings like this to change default configuration path of Realm from Document to Library directory for Xamarin iOS app:

// Get path of Library directory first

var directoryLib = Environment.GetFolderPath(Environment.SpecialFolder.Resources);

//Configure your own path

var myOwnRealmPath = Path.Combine(directoryLib, "boards.realm");
RealmConfiguration.GetPathToRealm(myOwnRealmPath);

// Change default configuration path to your own (Here I have changed to Library directory)

RealmConfiguration.DefaultConfiguration = new RealmConfiguration(myOwnRealmPath);

//Get Realm Instance from your own designed path

_realm = Realm.GetInstance(RealmConfiguration.DefaultConfiguration);
标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!