应用关闭时与服务器同步数据 [英] Sync data with server when app is closed

查看:144
本文介绍了应用关闭时与服务器同步数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有适用于Android和iOS的智能手机应用程序。我与服务器进行数据同步。我想在应用关闭时向服务器发送一些数据,例如用户的最后活动。如果应用程序再次打开,我知道该怎么做。在某些情况下,用户电话处于离线模式,没有可用的网络连接。因此数据存储在应用程序本地数据库中。用户关闭应用程序,没有数据同步。稍后网络连接返回。

I have smartphone app for Android and iOS. I have data syncronization going on with server. I want to send some data to server when app is closed, for example last activities of user. I know how to do it if app is opened again. In some situations users phone is in offline mode, no network connection is available. So data gets stored in apps local database. User closes app and no data is synced. Later on network connection returns.

所以我的主要问题。当应用关闭时,是否可以将同步与服务器排队,但网络连接是否可用?就像网络连接返回一样,手机会将数据发送到服务器。

So my main question. Is it possible to queue syncronization with server when app is closed, but network connection is available? Like as soon as network connection returns, phone sends data to server.

我正在使用混合框架Ionic。我在应用程序中的数据存储在SQLite中。

I'm using hybrid framework Ionic. My data in app is stored in SQLite.

推荐答案

没有应用程序关闭事件可用。您可以使用的是平台暂停事件。

There are no app close event available. What you can use would be a platform pause event.

constructor( private platform: Platform ) {
    platform.ready().then(() => {    
        this.platform.pause.subscribe(() => {
            console.log('[INFO] App paused');
        });

    });
 }

这篇关于应用关闭时与服务器同步数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆