【问题标题】:Is there any Background service for synchronizing my SQLite data to server in ionic 2?是否有任何后台服务可用于将我的 SQLite 数据同步到 ionic 2 中的服务器?
【发布时间】:2017-04-11 07:06:39
【问题描述】:

我创建了一个 ionic 2 应用程序,它将数据保存到 SQLite 存储中以供离线模式访问。当手机有互联网连接时,我应该能够将所有 SQLite 数据同步回服务器。

我怎样才能做到这一点?

【问题讨论】:

    标签: cordova angular ionic2 cordova-plugins


    【解决方案1】:

    最好的方法是在你的 app.component.ts 中添加一个Resume Method,这样每次你的应用程序启动时,从后台或新启动或其他将触发该功能。在此功能中,您检查设备是否具有 Internet。如果 Internet 可用,请检查所有内容是否已同步或新数据是否可用。如果新数据可用,则将其发送到您的服务器并存储。

    您可以像这样添加简历方法:

      initializeApp(){
        this.platform.ready().then(() => {
          document.addEventListener('resume', () => { 
            //HERE IS YOUR ONRESUME CODE
            //Get your Storage and check if something has changed
            //Check if Internet is aviable
            //Send Data to your Server
     });
    .....................
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2011-11-02
      • 2018-04-03
      • 1970-01-01
      • 2017-12-10
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多