realm-swift icon indicating copy to clipboard operation
realm-swift copied to clipboard

Support app group container with synchronized Realm

Open ewerx opened this issue 8 years ago • 26 comments

Goals

I am currently sharing a realm db between an iOS app and its today widget extension by storing the realm in the application group container directory and setting this path in the Realm configuration's fileURL:

var config = Realm.Configuration()
config.fileURL = FileManager.default.containerURL(forSecurityApplicationGroupIdentifier: appGroupIdentifier)!.appendingPathComponent(dbFilename)
Realm.Configuration.defaultConfiguration = config

Now I want to add cloud sync features to the app using Realm Mobile Platform, but it is not possible to specify both a fileURL and a syncConfiguration in the Configuration. How can I enable synchronization and have both the app and extension continue to access the existing db that's stored in the group container?

Related StackOverflow question (not mine): https://stackoverflow.com/questions/40785346/swift-realm-mobile-platform-today-extension

Expected Results

It's possible to synchronize a Realm db stored in the app group container directory.

ewerx avatar Dec 26 '16 17:12 ewerx

Thanks for getting in touch with us!

If you plan to have some synced database X being used by both the app extension and the main app, you can have each one open a separate copy and sync will keep them up to date. I don't think sync currently supports migrating a non-synced Realm directly to a synced Realm, although all of this will be changing in the near future.

Hope that helps!

austinzheng avatar Dec 27 '16 20:12 austinzheng

So if I understand correctly, both app extension and the app should specify a SyncConfiguration to access the remote db instead of using the app group container, and each will maintain their own separate local cache of the db for offline access?

One disadvantage to this approach is that the app extension requires internet access to remain synchronized with the parent app. If the device is offline the widget/extension will remain out of sync until a connection is re-established.

That's not a showstopper in my case, but if there's currently no way to migrate existing local Realm db data to a synced Realm I will have to postpone deploying cloud sync features or look at other options like implementing sync via CloudKit on my own.

ewerx avatar Dec 27 '16 21:12 ewerx

Yes, that's the situation as it currently stands. We're definitely interested in ways to make the use case you described easier to implement, though, and I'll pass your feedback along. Thanks!

austinzheng avatar Dec 27 '16 23:12 austinzheng

Thanks. It would definitely be useful to be able to sync a realm and store the local db in the app group container for extension access. If this is not already on the roadmap I would like to make a feature request to keep track of its status.

ewerx avatar Dec 28 '16 16:12 ewerx

Thanks for your feedback. I'll add it to our backlog.

austinzheng avatar Dec 28 '16 18:12 austinzheng

Are there any further updates on this issue?

I am sharing the local db with the today widget and Watch, so it would be good if it was possible to synchronize a Realm db stored in the app group container directory, even if migrating a non-synced Realm directly to a synced Realm was not supported.

brock190 avatar May 10 '17 10:05 brock190

This issue is still in our backlog because, for technical and business reasons, we've prioritized other issues ahead of it. If that changes we'll update this thread.

austinzheng avatar May 10 '17 16:05 austinzheng

Wow, I went through almost completely converting my app to Realm and then I saw this. Back to Core Data for me. Can't justify using two separate databases for app and app extension (sync is risky enough between devices - don't need to risk it on a single device, plus - two databases). Bummer. So disappointed right now.

inPhilly avatar Jun 14 '17 02:06 inPhilly

Core Data also doesn't support inter-process access unless you're willing to forgo fine-grained notifications. Although support for that appears to be coming in iOS 11.

jpsim avatar Jul 05 '17 21:07 jpsim

As an additional data point, we're also removing Realm from our app because of this issue.

xcodewarrier avatar Jul 08 '17 08:07 xcodewarrier

Out of interest it was claimed that this was solved back in 2015, what has changed? https://news.realm.io/news/thomas-goyne-fast-inter-process-communication/

xcodewarrier avatar Jul 08 '17 08:07 xcodewarrier

We are in the same boat having implemented synced realms, but no support for app group container directory is a showstopper as we cannot justify having a separate system for the app extension.

Are there any plans to support this in the near future?

brock190 avatar Jul 08 '17 09:07 brock190

The article linked above deals with non-synchronized Realms, which work differently from synchronized Realms in a number of ways that are usually not relevant to end users.

We have a very large list of things we'd like to add support for, but our sync engineers simply cannot make any guarantees at this time as to when this feature will be available. We regret the inconvenience.

austinzheng avatar Jul 08 '17 18:07 austinzheng

I was under the impression that apps with synchronized Realms use a local copy (whose location is not user-configurable) for all operations , and the sync logic happens behind the scenes (thus allowing seamless offline access to the db).

If there was an option to store this local copy in the app group container, would that be enough to allow extensions to access the main app's Realm directly without requiring their own synchronized Realm configuration and separate local copy?

Even restricting extensions to read-only access would still be useful, since extensions could request the parent app to make state changes.

ewerx avatar Jul 08 '17 19:07 ewerx

+1 @ewerx restricting extensions to read-only access would be more than sufficient for our needs

xcodewarrier avatar Jul 08 '17 22:07 xcodewarrier

The problem isn't figuring out where to store the file. The underlying problem is that the synchronization subsystem only works correctly if at most one instance of the sync client has the file open at any given time, and there's currently no way for Realm to coordinate between a parent app and extension process to ensure that this is true.

austinzheng avatar Jul 09 '17 00:07 austinzheng

If the Backlog label was replaced with an Enhancement label I wonder if it means it's on the roadmap =) The last comment made it sound almost unfeasible.

nightfall708 avatar Sep 13 '17 10:09 nightfall708

Any update on this ?

Alex293 avatar Dec 03 '17 10:12 Alex293

To reduce the file size now - is it handy to use partialSync for this ? At least it could reduce the file size. For a share extension which wants to write to the database thats also not very handy with a synched realm.

hakkurishian avatar Feb 05 '18 23:02 hakkurishian

any updates on this?

saito-sv avatar Jan 23 '20 23:01 saito-sv

does anyone have a workaround to use siri with sync realm?

rouuuge avatar Sep 21 '21 06:09 rouuuge

Hi @rouuuge Can you give explain a little bit in detail your use case?. If it is not related to supporting a synchronised realm in app group container, please create a new issue.

dianaafanador3 avatar Sep 23 '21 20:09 dianaafanador3

sorry just could solved it. I had to login on my app intent with the credentials I shared from the mainapp. so my use case is solved.

rouuuge avatar Sep 23 '21 20:09 rouuuge

It's been 5 years, any hope on this?

almas-ims avatar Mar 27 '22 15:03 almas-ims

We've a project scheduled to work on this in the coming quarters, so, there is hope.

jsflax avatar Mar 27 '22 15:03 jsflax

Any update on this? I’m just about to remove Realm completely from my app because updating Realm via the share extension while is a core function I want to add.

nick-condon avatar Oct 13 '23 03:10 nick-condon