我是Ionic框架的新手。我正在尝试如何在应用程序中集成指纹授权。
为此我在代码中添加了home.ts
文件:
import { Component } from '@angular/core';
import { NavController } from 'ionic-angular';
import { FingerprintAIO } from '@ionic-native/fingerprint-aio';
@Component({
selector: 'page-home',
templateUrl: 'home.html'
})
export class HomePage {
constructor(public navCtrl: NavController, private fingerPrint: FingerprintAIO) {
}
this.fingerPrint.show({
clientId: 'Fingerprint-Demo',
clientSecret: 'password', //Only necessary for Android
disableBackup:true, //Only for Android(optional)
localizedFallbackTitle: 'Use Pin', //Only for iOS
localizedReason: 'Please authenticate' //Only for iOS
})
.then((result: any) => console.log(result))
.catch((error: any) => console.log(error));
}
当我使用ionic cordova build android
进行Android构建时,出现以下错误:
typescript: src/pages/home/home.ts, line: 16
Unexpected token. A constructor, method, accessor, or property was expected.
L16: this.fingerPrint.show({
L17: clientId: 'Fingerprint-Demo',
[15:24:38] typescript: src/pages/home/home.ts, line: 25
Declaration or statement expected.
L24: .catch((error: any) => console.log(error));
Error: Failed to transpile program
如何解决此问题?
答案 0 :(得分:0)
将此代码放在constructor()
这样的内容中,
constructor(public navCtrl: NavController, private fingerPrint: FingerprintAIO) {
this.fingerPrint.show({
clientId: 'Fingerprint-Demo',
clientSecret: 'password', //Only necessary for Android
disableBackup:true, //Only for Android(optional)
localizedFallbackTitle: 'Use Pin', //Only for iOS
localizedReason: 'Please authenticate' //Only for iOS
})
.then((result: any) => console.log(result))
.catch((error: any) => console.log(error));
}
答案 1 :(得分:0)
constructor(public navCtrl: NavController, private fingerPrint: FingerprintAIO) {
this.initFigerprint();
}
initFigerprint(){
this.fingerPrint.show({
clientId: 'Fingerprint-Demo',
clientSecret: 'password', //Only necessary for Android
disableBackup:true, //Only for Android(optional)
localizedFallbackTitle: 'Use Pin', //Only for iOS
localizedReason: 'Please authenticate' //Only for iOS
})
.then((result: any) => console.log(result))
.catch((error: any) => console.log(error));
}