ios - Share Realm Data with WatchOS -


in project want use 1 realm database ios 10 application , watchos 3 application @ same time. did adding frameworks embedded binaries 3 different targets. happened work watchkit extension doesn't seem recognize objects created within ios environment. how possible have shared realm database between 2 devices?

update: okay, chrisamanse's heads-up, did more research on this.

it turns out app groups no longer possible on watchos 2. watch apps no longer run extensions on phone; 2 isolated processes without shared resources.

as such, means necessary maintain separate realm file on both watch , phone , communicate changes made either through watchconnectivity framework.


original: ios applications , extensions (both today widgets , watchos apps) need considered 2 wholly separate entities in own separate containers. default, extension cannot access files inside container of parent application. if you're saving realm file default path (i.e., 'documents' folder), there's no way watchos app access there.

thankfully, it's possible use 'app groups' feature of ios specify shared folder both parent ios app , watchos app can access, , can both read , write realm files in there.

once you've enabled app groups entitlement in app, it's matter of setting realm file's location point location.

let sharedcontainerurl = nsfilemanager.defaultmanager().containerurlforsecurityapplicationgroupidentifier("group.my.appgroups.bundleid")! let realmurl = sharedcontainerurl.appendingpathcomponent("sharedrealm.realm")  let realmconfiguration = realm.configuration() realmconfiguration.fileurl = realmurl let realm = try! realm(configuration: realmconfiguration) 

there's a tutorial on realm website explains how make work in more detail, api , swift version out of date @ point.


Comments

Popular posts from this blog

angular - Is it possible to get native element for formControl? -

unity3d - Rotate an object to face an opposite direction -

javascript - Why jQuery Select box change event is now working? -