锁定单个NSPersistentDocument [英] Locking a single NSPersistentDocument
问题描述
我的应用程序当前使用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?
推荐答案
As an alternative to locking the SQLite file, you could try using LSMultipleInstancesProhibited to disallow your users running two application instances.
缺点是,尽管他们不共享核心数据存储,但它也将阻止多个用户(快速用户切换)同时使用您的应用程序.
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.
这篇关于锁定单个NSPersistentDocument的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!