本文介绍了离子的混合应用,节省了应用程序状态/退出数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我建设使用带有棱角的js离子框架的应用程序,而我的最好的方法是什么,去保存和恢复用户状态,当他们退出应用程序有点困惑。例如,在iOS中,如果用户手动终止应用程序,或者如果手机关机出于某种原因,我希望用户能够打开我的应用程序了,仍然是在同一个地方,看到同样的数据,即使如果他们是脱机。

我一直在使用HTML的localStorage,并了解如何保存和恢复本地用户的数据,同样我知道如何保存到其当前状态的参考。当用户实际使用的应用程序不过我会需要被拉动和从云数据库将数据推,所以我才真正使用本地存储,当他们退出时保存用户状态。

什么是去节省角其状态的最好方法?当我应该这样做,而且是他们的方式来判断,当应用程序被终止。理想情况下,我想能够调用一个函数来保存状态正确的应用程序终止之前,但我一直无法找到角度做到这一点的正确方法。

由于这是一个相当具体的问题,林希望能学会做正确的方式。谢谢!

林找什么

  // P小号üD 0 C 0 D E
在('application_exit',函数(){
    //保存用户数据
})


解决方案

您可以用科尔多瓦暂停事件,只要您的应用程序发送到后台被触发。

document.addEventListener(暂停,yourCallbackFunction,FALSE);

您会想看看iOS的怪癖,确保但它们适合你的使用情况。

I'm building an app using the ionic framework with angular js, and I'm a little confused on what the best way is to go about saving and restoring the users state when they exit the app. For example, in iOS if the user manually terminates the app, or if the phone is turned off for some reason, I want the user to be able to open my app up and still be at the same place and see the same data, even if they are offline.

I have been using HTML localstorage, and understand how to save and restore the users data locally, and similarly I understand how to save a reference to their current state. When the user is actually using the app however I'm gonna need to be pulling and pushing data from a cloud database, so I would only really use the local storage to save the users state when they exit.

What is the best way to go about saving their state in angular? When should I do it, and is their a way to tell if and when the app is terminating. Ideally I would like to be able to call a function to save the state right before the app terminates, however I have been unable to find the right way to do this in angular.

As this is a fairly specific issue, Im hoping to learn to right way to do it. Thanks!!

What Im looking for

// P S U D O    C O D E
on('application_exit', function(){
    // save user data
})
解决方案

You can use the Cordova "pause" event, which is triggered whenever your app is sent to the background.

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

http://docs.phonegap.com/en/2.9.0/cordova_events_events.md.html#pause

You'll want to look at the iOS quirks to make sure they fit your use case, however.

这篇关于离子的混合应用,节省了应用程序状态/退出数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-06 00:07