Using TouchID on Ionic 2

强颜欢笑 提交于 2020-01-03 04:40:09

问题


I am trying to use TouchID within my Ionic 2 app and have this simplified code.

When I run the app on my iPhone I see "A" is logged in the console and then "Fingerprint or device passcode validated."
but "B" is not logged. What have I missed?

checkIn(job) {
    console.log("A");
    TouchID.verifyFingerprint('Scan your fingerprint to check in')
    .then(
      res => function() {  
        console.log("B");
      },
      err => alert('Sorry, your fingerprint is not recognised')
    );  

} 

回答1:


I am assuming you have imported Touch ID Plugin into your project using

import { TouchID } from 'ionic-native';

In your CheckIn function first check for Touch ID Availability using

TouchID.isAvailable()
.then(
  res => console.log('TouchID is available!'),
  err => console.error('TouchID is not available', err)
);

If it logs 'TouchID is available!' then in your TouchID.verifyFingerprint function log err to pinpoint the issue

TouchID.verifyFingerprint('Scan your fingerprint please')
.then(
  res => console.log('Ok', res),
  err => console.error('Error', err)
);

Error Codes

The plugin will reject for various reasons. Your app will most likely need to respond to the cases differently.

Here is a list of some of the error codes:

  • -1 - Fingerprint scan failed more than 3 times
  • -2 or -128 - User tapped the 'Cancel' button
  • -3 - User tapped the 'Enter Passcode' or 'Enter Password' button
  • -4 - The scan was cancelled by the system (Home button for example)
  • -6 - TouchID is not Available
  • -8 - TouchID is locked out from too many tries


来源:https://stackoverflow.com/questions/41149395/using-touchid-on-ionic-2

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!