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

心不动则不痛 提交于 2019-12-03 20:59:58

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