锁定单个 NSPersistentDocument

发布于 2024-08-15 12:17:55 字数 252 浏览 2 评论 0原文

我的应用程序当前使用 CoreData 作为后端来存储到存储在 ~/Library/Application Support/MYAPP/MyDataFile.sqlite 中的单个 SQL 数据文件。我知道这是一种不寻常的情况,但是“锁定”此文件的最佳方法是什么,这样如果用户决定(出于任何愚蠢的原因)运行我的应用程序的第二个副本,Core Data 就不会惊慌失措?我应该使用一些老派的东西,比如在某个地方写一个锁文件并检查它,还是有更好的可可方法来做到这一点?

My application currently uses CoreData as a backend to store to a single SQL data file stored in ~/Library/Application Support/MYAPP/MyDataFile.sqlite. I know it's an unusual situation, but what is the best way to "lock" this file so that if the user decides (for whatever silly reason) to run a second copy of my app, Core Data won't freak out? Should I use something old school like writing a lockfile somewhere and checking for that, or is there a nicer more Cocoa way of doing this?

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

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

发布评论

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

评论(1

離殇 2024-08-22 12:17:55

作为锁定 SQLite 文件的替代方法,您可以尝试使用 LSMultipleInstancesProhibited 禁止您的用户运行两个应用程序实例。

编辑:缺点是它还会阻止多个用户(快速用户切换)同时使用您的应用程序,尽管他们不共享核心数据存储。

As an alternative to locking the SQLite file, you could try using LSMultipleInstancesProhibited to disallow your users running two application instances.

Edit: the downside is it will also prevent multiple users (fast user switching) from using your application concurrently, although they do not share the core data store.

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