简体   繁体   English

交付具有已启用读写功能(也是预填充)的sqlite数据库的iOS应用

[英]Shipping an iOS app with a read-write enabled (also pre-filled) sqlite database

This is the first time I'm developing for iOS. 这是我第一次为iOS开发。 I need my app to ship with a pre-filled sqlite database which a user will read from and write to. 我需要我的应用程序附带一个预填充的sqlite数据库,用户可以从中读取和写入该数据库。 How should I go about deploying this? 我应该如何进行部署? Can experienced developers help me? 有经验的开发人员可以帮助我吗?

What I thought was this: I create and pre-fill the database in my development machine, add it to my app bundle. 我的想法是:我在开发机器中创建并预填充数据库,然后将其添加到应用程序包中。 During app initialization in device, I check if I have a database in NSDocumentDirectory of my app. 在设备中的应用程序初始化期间,我检查我的应用程序的NSDocumentDirectory中是否有数据库。 If not, I copy the database in the bundle to NSDocumentDirecory and read from/write into it. 如果没有,我将捆绑软件中的数据库复制到NSDocumentDirecory并从中读取/写入。 If I have a db there, I just use it. 如果我在那里有一个数据库,我就用它。

Is this a bad idea? 这是一个坏主意吗? Any pitfalls I'm falling in here? 我有什么陷阱吗?

I have an app that does something pretty similar to that. 我有一个应用程序,其功能与此相似。 Mine doesn't allow writing to the database, but I don't see why it would be hard. 我的不允许写数据库,但是我不明白为什么会很难。

I have a dataset that I import into a SQLite database, copy it into the apps directory, put the DB filename into a constant and it seems to work really well. 我有一个数据集,我将其导入到SQLite数据库中,将其复制到apps目录中,并将数据库文件名放入一个常量中,并且看起来工作得很好。

I change the SQLite filename each time I put it in there (MyDB62020111.sqlite -> MyDB62020112.sqlite) just to make sure that I avoid a problem where it thinks that the file is already in the NSDocumentDirectory and not update it. 每次将SQLite文件名放在其中时,我都会对其进行更改(MyDB62020111.sqlite-> MyDB62020112.sqlite),以确保避免出现认为文件已存在于NSDocumentDirectory中而不更新的问题。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM