简体   繁体   English

仅在首次安装后运行的方法

[英]method that runs only after first install

I am creating an app that get data from the server then save it and work locally with sqlite. 我正在创建一个应用程序,该应用程序从服务器获取数据,然后将其保存并在sqlite本地工作。

I want to initialize my application with data loaded only after the first installation, saved to sqlite and then loaded from database. 我想使用仅在第一次安装后加载的数据来初始化我的应用程序,然后将其保存到sqlite,然后从数据库加载。 For that i want to create a method that save the data locally, how to make sure this method runs only after the first time the user install the app. 为此,我想创建一种在本地保存数据的方法,如何确保仅在用户首次安装应用程序后才运行此方法。

I think that the easier way to do this is to check, at every application run, if your database contains a certain value in a config table: if isn't present, populate the db, otherwise do nothing and continue execution. 我认为,执行此操作的更简单方法是在每次运行应用程序时检查数据库中配置表中是否包含某个值:如果不存在该值,则填充数据库,否则不执行任何操作并继续执行。

In this way you could avoid to write platform specific code (native) since you're doing everything from the js layer. 这样,您可以避免编写平台特定的代码(本机),因为您要从js层进行所有操作。

Obviously I'm supposing that you're already using sqlite in Cordova, and that you can execute sql query/insert from js. 显然,我假设您已经在Cordova中使用sqlite,并且可以从js执行sql查询/插入。

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

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