应用关闭前的离子运行功能 [英] Ionic run function before app closes

查看:70
本文介绍了应用关闭前的离子运行功能的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是否可以调用某种函数来侦听该应用程序是否要退出,关闭或进入后台.基本上,任何表示用户已停止使用该应用程序"的事件都是如此?

Is there some kind of function that I can call that listens to whether the app is about to exit, or close or go into the background.. Basically any event that means "the user has stopped using the app"?

我是我的应用程序,我建立了一个用户日志",用于跟踪用户在应用程序中浏览时的情况.我不想在这些事件发生时不断地向服务器发送少量数据,而是想在用户停止使用该应用程序之前一次性发送整个批处理(同样,这是否意味着完全关闭该应用程序,然后将其发送给背景等.

I'm my app I build up a 'user log' that tracks the user as they are navigating through the app. Instead of sending little pieces of data constantly to the server as these events occur, I want to send off the whole batch in one go just before the user stops using the app (again, whether that means closing the app completely, sending it to the background etc.)

最后,如果确实存在这样的功能,那么您将该功能放在哪里?在您的app.js中?还是必须在应用程序的每个控制器中都放置该侦听器?

And lastly, if such a function does indeed exist.. where do you put that function? In your app.js? Or do you have to put that listener in every single controller of your app?

推荐答案

您可以从Cordova文档中查看此事件列表:

You can check this events list from Cordova docs:

https://cordova.apache.org/docs/zh/5.4.0/cordova/events/events.html

尤其是暂停事件 :

将应用程序置于后台时触发该事件.

The event fires when an application is put into the background.

document.addEventListener("pause",yourCallbackFunction,false);

document.addEventListener("pause", yourCallbackFunction, false);

这篇关于应用关闭前的离子运行功能的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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