[英]Using Cordova Plugins in Ionic Inside a Controller
So I am trying to integrate touch authentication into my app. 因此,我正在尝试将触摸身份验证集成到我的应用程序中。 I took a look at this article http://ourcodeworld.com/articles/read/190/how-to-use-fingerprint-authentication-in-cordova-phonegap-ionic-for-android-and-ios and it looked like exactly what I wanted. 我看了一下这篇文章http://ourcodeworld.com/articles/read/190/how-to-use-fingerprint-authentication-in-cordova-phonegap-ionic-for-android-and-ios ,它看起来像正是我想要的。 It used this https://github.com/mjwheatley/cordova-plugin-android-fingerprint-auth.git and https://github.com/EddyVerbruggen/cordova-plugin-touch-id plugin. 它使用了这个https://github.com/mjwheatley/cordova-plugin-android-fingerprint-auth.git和https://github.com/EddyVerbruggen/cordova-plugin-touch-id插件。
Now this is when you find out I'm a newb with Angular and Ionic. 现在这是当您发现我是Angular和Ionic的新手时。 How do I pass those functions into the controller, so that I can have something like this: 我如何将这些函数传递到控制器中,这样我可以得到如下内容:
.controller('LoginController', function ($rootScope, $scope, $touchAuth) {
$touchAuth.isAvailable(
function() {
alert('available!')
}, // success handler: TouchID available
function(msg) {
alert('not available, message: ' + msg)
} // error handler: no TouchID available
$touchAuth.verifyFingerprint(
'Scan your fingerprint please', // this will be shown in the native scanner popup
function(msg) {
alert('ok: ' + msg);
}, // success handler: fingerprint accepted
function(msg) {
alert('Something is wrong: ' + JSON.stringify(msg));
} // error handler with errorcode and localised reason
})
Basically what I want to know is how can I use these functions these plugins provide within my controllers? 基本上我想知道的是如何使用这些插件在控制器中提供的这些功能?
you can do this by making service or factory 您可以通过服务或工厂来做到这一点
assuming this that you have installed the plugin successfully from : https://github.com/mjwheatley/cordova-plugin-android-fingerprint-auth 假设您已经从以下位置成功安装了插件: https : //github.com/mjwheatley/cordova-plugin-android-fingerprint-auth
you can use this in this way 你可以这样使用
make a factory of $touchAuth 建立$ touchAuth的工厂
.factory('$touchAuth', function () {
return {
isAvailable : function(isAvailableSuccess, isAvailableError){
FingerprintAuth.isAvailable(isAvailableSuccess, isAvailableError);
}
}
})
Now inject ' $touchAuth ' in your controller and then use it as the same way : 现在在控制器中注入' $ touchAuth ',然后以相同的方式使用它:
.controller('LoginController', function ($rootScope, $scope, $touchAuth) {
$touchAuth.isAvailable(
function() {
alert('available!')
},
function(msg) {
alert('not available, message: ' + msg)
}
})
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.