【问题标题】:Ionic Cordova FingerPrint Authentication离子科尔多瓦指纹认证
【发布时间】:2020-11-20 02:52:31
【问题描述】:

我是 Ionic 的新手。我需要有关在我的应用程序中设置指纹和/或密码身份验证的帮助。我使用了 Android Fingerprint Auth Cordova 插件。在我的安卓设备上运行它时,它工作正常,但是,它有一个取消按钮,当用户点击它时,它会打开应用程序。我想禁用此取消按钮并阻止用户进入应用程序。

下面是代码:

import { Component } from '@angular/core';
import { AndroidFingerprintAuth } from '@ionic-native/android-fingerprint-auth/ngx';

import { Platform } from '@ionic/angular';
import { SplashScreen } from '@ionic-native/splash-screen/ngx';
import { StatusBar } from '@ionic-native/status-bar/ngx';

@Component({
  selector: 'app-root',
  templateUrl: 'app.component.html',
  styleUrls: ['app.component.scss']
})
export class AppComponent {
  constructor(
    private platform: Platform,
    private splashScreen: SplashScreen,
    private statusBar: StatusBar,
    public androidFingerprintAuth: AndroidFingerprintAuth
  ) {
    this.initializeApp();
  }

  initializeApp() {
    this.platform.ready().then(() => {
      this.statusBar.styleDefault();
      this.splashScreen.hide();
      this.androidFingerprintAuth.isAvailable()
  .then((result)=> {
    if(result.isAvailable){
      // it is available

      this.androidFingerprintAuth.encrypt({ clientId: 'myAppName', username: 'myUsername', password: 'myPassword',maxAttempts:5,dialogTitle:'Confirm finger print to continue',userAuthRequired:true })
        .then(result => {
           if (result.withFingerprint) {
               console.log('Successfully encrypted credentials.');
               console.log('Encrypted credentials: ' + result.token);
           } else if (result.withBackup) {
             console.log('Successfully authenticated with backup password!');
           } else console.log('Didn\'t authenticate!');
        })
        .catch(error => {
           if (error === this.androidFingerprintAuth.ERRORS.FINGERPRINT_CANCELLED) {
             console.log('Fingerprint authentication cancelled');
           } else console.error(error)
        });

    } else {
      // fingerprint auth isn't available
    
    }
  })
  .catch(error => console.error(error));
    });
  }
}

请建议如何禁用取消按钮。

谢谢。

【问题讨论】:

  • 有登录页面吗?这个代码在哪里使用?在第一页之后的第一页?

标签: angular cordova ionic-framework cordova-plugins ionic-native


【解决方案1】:

Android 指纹验证 v1.5.0 的当前版本没有配置来禁用“关闭”按钮,甚至从提供的对话框组件重定向或关闭应用程序。目前,大多数在激活时显示某种 UI 的插件会在它们关闭或“销毁”时重定向到应用程序。您可以使用选项对象中设置为 false 的“disableBackup”属性修改“使用备份”按钮,它将删除该按钮。

【讨论】:

    【解决方案2】:

    谢谢,但我找到了答案。为了禁用或隐藏取消按钮,我对插件文件夹中的 FingerprintAuthenticationDialogFragment.java 文件进行了更改以隐藏/禁用取消按钮,如下所示:

    路径: ProjectPath>\platforms\android\app\src\main\java\com\cordova\plugin\android\fingerprintauth\FingerprintAuthenticationDialogFragment.java

    代码更改:

     int cancel_button_id = getResources()
                    .getIdentifier("cancel_button", "id", FingerprintAuth.packageName);
            mCancelButton = (Button) v.findViewById(cancel_button_id); 
    // Added below lines of code for hiding/disabling cancel button
    > mCancelButton.setVisibility(View.GONE); 
    >         mCancelButton.setEnabled(false);
    

    谢谢

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-06-03
      • 2016-08-30
      • 1970-01-01
      • 2020-09-10
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多