锁定一个PhoneGap的Andr​​oid应用程序使用PIN code [英] Locking a PhoneGap Android app with a PIN code

查看:132
本文介绍了锁定一个PhoneGap的Andr​​oid应用程序使用PIN code的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用 的PhoneGap构建应用程序。我想为它本身就带有PIN的code锁定(它必须是一个在应用程序锁,从原生的Andr​​oid锁分开)在下列情况下:

I'm using PhoneGap to build an app. I'd like for it to lock itself with a PIN-code (it has to be an in-app lock, separate from the native Android lock) in the following cases:


  • 的时间一定数额没有用户输入传递

  • 如果应用程序最小化,或者电话留给周围铺设了一段时间,屏幕将自动关闭该用户导航离开这个程序,例如。

问题:


  • 我假设的电话超时和关闭屏幕将触发的暂停事件,但它确实是如何工作的?

  • 是否有可能运行一个的setInterval()功能,即使手机是为了检查与服务器推的的通知的?我感兴趣的是Android的唯一,我知道的iOS有一些怪癖。

  • 最后,什么是去实施PIN锁的最好方法?覆盖当前的界面或应用重定向到一个锁定页,而想起了原来的页面还是怎么了?

  • I'm assuming the the phone timing out and turning off the screen will trigger the pause event, but is that really how it works?
  • Is it possible to run a setInterval() function to run even when the phone is "paused" in order to check with a server to push notifications? I'm interested in Android only, I know iOS has some quirks.
  • Finally, what is the best way to go about implementing a PIN-lock? Overlay the current interface or redirect the app to a "lock page," while remembering the original page or something?

推荐答案

我没有任何code的例子,但我可以讨论的理论的实现。

I dont have any code examples, but I can discuss a theoretical implementation.

我会亲自执行锁定屏幕,在应用程序的开放。为了保持一致,该应用程序是一个基于PIN的应用程序(可怕的字眼,我知道)。所以每当应用程序是第一次公开,就应该问的针数。

I would personally implement the locking screen, at the opening of the app. To maintain consistency that the app is a PIN based app (awful wording I know). So whenever the app is first open, it should ask for the pin number.

在实施重定向,我会用背法往回走(DevExtreme有一个默认的背法,我不知道如果PhoneGap的有一个或没有)

When Implementing the redirection, I would use the Back Method to go backwards (DevExtreme has a default back method, I'm not sure if phonegap has one or not)

试图访问背面方法,如果失败。继续向前发展。

Attempt to access the back method, if it fails. Proceed forward.

做到这一点使用try / catch语句,尽量回去,如果它的错误承担其示数,因为没有去哪里回。进到主屏幕。

Accomplish this using a try/catch, try to go back, if it errors assume its erroring because there is no where to go back to. Proceed to home screen.

实施方法的onPause设备暂停后移动到锁屏。

Implement the onPause method to move to the lock screen after the device pauses.

如果你没有一个默认的背法继承人模拟了使用伪code实现一个

if you don't have a default back method heres a mock up on implementing one using pseudo code

为了创造我们要去劫持的导航方法,或者更好的样机我们要重新创建导航方法,但仍使用现有的方法。

in order to create the mockup we're gonna hijack the the navigation method, or better yet we're gonna recreate the navigation method, but still use the existing method.

define backstring = ""

function NavigateTo(string navigateto)
    backstring = currentnavigationscreen
    this.Navigate(navigateto)
end

此方法设置backstring的价值,并导航到下一个屏幕

this method sets the value of the backstring and navigates to the next screen

function GoBack()
    NavigateTo(backstring)
end

这是在onPause方法应该是什么样子。

this is what the onpause method should look like

function onPause()
    NavigateTo("lockscreen")
end

我当然希望这会有所帮助。

I certainly hope that this helps.

而不是做一个尝试,风风火火的回功能,你也chould创建CanBack()方法。

Instead of doing a try and catch on the back function, you chould also create a CanBack() method.

function CanBack()
    return (backstring.length > 0)
end

引用

根据您的应用程序的屏幕流,你可能还需要禁用
  后退按钮功能,以prevent用户从逃脱你
  锁定模式。 - 加西亚·乌尔塔多

Depending on the screen flow of your app, you may need to also disable the back button functionality to prevent the user from "escaping" your lock modal. – Garcia Hurtado

这是一个很好的点,但是如果你坚持使用伪code我放弃,不要把它连接到后退按钮机制,你将被罚款。只要确保在您导航到密码屏幕,你把它的根。

This is an excellent point, however if you stick with the pseudo-code I gave and don't connect it to the back button mechanism you will be fine. Just make sure when you navigate to the password screen, you treat it as the root.

您还可以创建一个叠加,并简单地认为,确定是否显示与否一个布尔值。缺省值可能是真实的,所以每一个应用程序打开时,你必须输入通code。你可以使用的onPause函数来设置布尔值false,以告知其需要再次锁定的应用程序。

You could also create an overlay, and simply maintain a boolean that determines whether to display it or not. The default value could be true, so every time the app is opened you have to enter the passcode. And you can use the onpause function to set the boolean to false to inform the app that it needs to be locked again.

这篇关于锁定一个PhoneGap的Andr​​oid应用程序使用PIN code的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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