Where to put SQLite database to keep it from being over-ridden during update on OS X?

纵然是瞬间 提交于 2020-01-01 07:07:54

问题


I'm developing my first OS X application which will be distributed through Mac App Store.

The app makes use of an sqlite database which I am currently keeping on the same location as the rest of app file dependencies.

I'm using Qt Framework to develop the application.

Keeping within the boundaries of App Store rules;

  • Where can I locate the database file for it not to be overridden during app updates?

  • How should I structure the .app folder and all the dependencies?

Thank you.


回答1:


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.

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];

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


来源:https://stackoverflow.com/questions/14123126/where-to-put-sqlite-database-to-keep-it-from-being-over-ridden-during-update-on

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!