哪里放置SQLite数据库以防止在OS X上的更新过程中覆盖它? [英] Where to put SQLite database to keep it from being over-ridden during update on OS X?
问题描述
我正在开发第一个OS X应用程序,该应用程序将通过Mac App Store分发.
I'm developing my first OS X application which will be distributed through Mac App Store.
该应用程序利用了sqlite数据库,该数据库目前与其他应用程序文件依赖项位于相同的位置.
The app makes use of an sqlite database which I am currently keeping on the same location as the rest of app file dependencies.
我正在使用Qt Framework开发应用程序.
I'm using Qt Framework to develop the application.
始终遵守App Store规则;
Keeping within the boundaries of App Store rules;
-
在哪里可以找到在应用程序更新期间不被覆盖的数据库文件?
Where can I locate the database file for it not to be overridden during app updates?
我应该如何构建.app文件夹和所有依赖项?
How should I structure the .app folder and all the dependencies?
谢谢.
推荐答案
您的问题暗示您正在写入sqlite数据库,这是一个坏主意,因为该应用程序将存储在以下位置:用户可能没有写权限.
Your question implies that you are writing to the sqlite database, which is a bad idea given the application will be stored in a location (/Applications
) that the user may not have write-access to.
您应该做的是在第一次使用时(或当您发现数据库不存在时)将数据库复制/创建到用户可写区域(应用程序容器的Documents
文件夹将执行).
What you should do is copy/create the database to a user-writable area (the Documents
folder of the app's container will do) upon first use (or when you detect it's not there) and use it from there.
编辑:为了获取文档"目录,请使用以下代码:
EDIT: In order to get the Documents directory use this code:
NSString *documentDir = [NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES) objectAtIndex:0];
这将为您提供应用容器Documents
目录的位置,而不是在对应用进行沙箱处理时的用户文档目录的位置:
This will give you the location of the app container Documents
directory, not the user's Documents directory when the app is sandboxed:
~/Library/Containers/com.yourdomain.yourapp/Data/Documents
这篇关于哪里放置SQLite数据库以防止在OS X上的更新过程中覆盖它?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!