【发布时间】:2017-04-11 07:06:39
【问题描述】:
我创建了一个 ionic 2 应用程序,它将数据保存到 SQLite 存储中以供离线模式访问。当手机有互联网连接时,我应该能够将所有 SQLite 数据同步回服务器。
我怎样才能做到这一点?
【问题讨论】:
标签: cordova angular ionic2 cordova-plugins
我创建了一个 ionic 2 应用程序,它将数据保存到 SQLite 存储中以供离线模式访问。当手机有互联网连接时,我应该能够将所有 SQLite 数据同步回服务器。
我怎样才能做到这一点?
【问题讨论】:
标签: cordova angular ionic2 cordova-plugins
最好的方法是在你的 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
});
.....................
【讨论】: