有关在应用程序NSPERSISTANTCLOUDKIT容器或应用程序组之间共享数据的建议或两者?

发布于 2025-02-03 08:50:27 字数 400 浏览 5 评论 0原文

我有几个不同的应用程序,我想与同一设备和跨设备上的个人核心数据存储共享一个个人核心数据存储。我一直在尝试NspersistentCloudkitContainer,这似乎有效,但是同步可能需要一段时间,而且何时何时清楚。我还尝试了使用将SQLite文件放置在组文件夹中的应用程序组,以便更改设备上的其他应用程序。 我的问题是要做一个,还是另一个或两者兼而有之。在访问共享SQLITE的同一设备上开放两个应用程序会导致冲突问题吗?如果我已经与共享组同步,我甚至需要将数据与CloudKit同步?仅使用NsperSistentCloudkitContainer,这意味着每个应用程序将在本地同步自己的数据副本,这似乎不是很有效,我再次不知道当我打开另一个应用程序时是否同步。但是,当我同时打开两个应用程序时,我已经看到了冲突。当一个应用程序进入后台时,是否有一种万无一失的方法可以防止冲突?

I have several different apps that I'd like to share a personal core data store with on the same device and across devices. I've been experimenting with NSPersistentCloudKitContainer, which seems to work, but it can take a while to sync and it's not clear when it has. I have also experimented with using app groups where the SQLite file is placed in a group folder so that changes are immediately available to other apps on the device.
My question is whether it is better to do one, or the other or both. Will two apps open on the same device accessing the shared SQLite cause conflict issues? Do I even need to sync data with cloudKit if I'm already syncing with a shared group? Using NSPersistentCloudKitContainer alone means that each app will be syncing its own copy of the data locally, which doesn't seem very efficient and again I don't know if it's synched when I open the other app up. But I have seen conflicts when I have both apps open at the same time. Is there a foolproof way to prevent conflicts when one app goes into the background?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

苍景流年 2025-02-10 08:50:27

应用程序组和CloudKit彼此正交。他们解决了不同的问题,您可以根据要做的事情使用一个或另一个或两者。应用程序组非常适合在一台设备上共享数据,并且CloudKit在多个设备上工作。如果您希望这两种事情都会发生,则可以同时使用两者。它不是一个或另一个,它是一个或两者都取决于应用程序。

避免冲突的唯一万无一失的方法是不要在多个地方编辑相同的数据。由于这两种情况可能都不会发生,因此最好查看如何解决冲突时。核心数据具有几种内置合并策略来解决冲突的变化,如果您想要不同的东西,可以编写自己的内容。

使用CloudKit,您的应用将在可用的新更改时通知您的应用。然后合并更改,并让合并政策处理冲突。使用应用程序组没有外部更改的通知,因此,最佳方法是在应用程序进入前景时检查新数据(如果将其编辑为其他地方)。

如果您看到冲突您不知道如何解决,请发布一个单独的问题,其中包含问题的详细信息,有人可能会为此提供帮助。

App groups and CloudKit are orthogonal to each other. They solve different problems and you can use one or the other or both depending on what you want to do. App groups are good for sharing data on one device, and CloudKit works across multiple devices. You can use both if you want both of those things to happen. It's not one or the other, it's either one or both depending on the app.

The only foolproof way to avoid conflicts would be to never edit the same data in more than one place. Since that probably won't happen with either of these, it's better to look at how to resolve conflicts when they arise. Core Data has several built in merge policies to resolve conflicting changes, and you can write your own if you want something different.

With CloudKit your app will be notified when new changes are available. Merge changes then, and let the merge policy deal with conflicts. With app groups there's no notification of external changes, so the best approach is to check for new data whenever the app comes to the foreground (in case it was edited somewhere else).

If you're seeing conflicts you don't know how to resolve, post a separate question with details of the problem and someone can probably help with it.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文