不知道您需要在本地存储多少数据,但如果您可以将其限制为5MB,则可以使用json
和localStorage
而不是本地数据库。
当您的应用程序提出数据请求时,请一次全部使用时间戳将其全部返回,并使用它来巧妙地仅返回更新的数据。像yourhost.com/retrieveData
这样的调用将返回所有数据,并且yourhost.com/retrieveData/timestampParam
仅返回时间戳后更新的数据。
返回类似:
{ "table1" : [{"col1":"data1","col2":"data2"},{"col1":"data3","col2":"data4"}],
"table2" : [{"col3":"data5","col4":"data6"},{"col3":"data5","col4":"data6"}],
"timestamp" : 1234567 } //this should be optimized for your needs, it's just a generic example.
当应用程序开始之前,什么都做的东西沿着这些路线,你会确保您的应用始终保持最新状态:
Check if the data is stored
If there isn't, or if the user is online or if the timestamp is too old, or you can perform any check you might need here
Retrieve the data again using the stored timestamp
Update the local data
Store the timestamp returned
If none of the above applies, the app is good to run
我在几个应用程序中使用该方法。我通过数据库选择了它,因为它更易于实施和维护。
json中的所有数据肯定会大于5MB。每个文件/对象的限制总计是5MB还是5MB? – SomethingOn
5MB是可以保存在本地存储上的最大数据大小。但AFAIK你也有限的网络SQL,5MB的iOS(可以扩展到10,如果用户授权)和12MB的Android如果我记得没错。需要搜索以确保虽然。当我回家时我会尽力找到一些东西。但是,如果你需要的不仅仅是这些,我相信你将不得不本土化。 – caiocpricci2
感谢caiocpricci2,我实际上希望使用PG-SQLite插件https://github.com/pgsqlite/PG-SQLitePlugin-iOS,但我无法使插件与我的项目一起工作:s – SomethingOn