awesome-cordova-plugins/src/plugins/touchid.ts

95 lines
4.1 KiB
TypeScript
Raw Normal View History

2015-12-02 09:06:38 +08:00
import {Plugin, Cordova} from './plugin';
2016-02-18 05:32:34 +08:00
/**
* @name TouchID
* @description
2016-02-18 05:32:34 +08:00
* Scan the fingerprint of a user with the TouchID sensor.
*
* Requires Cordova plugin: `cordova-plugin-touch-id`. For more info, please see the [TouchID plugin docs](https://github.com/EddyVerbruggen/cordova-plugin-touch-id).
*
* ### 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
*
2016-02-18 05:32:34 +08:00
*/
2015-12-02 09:06:38 +08:00
@Plugin({
plugin: 'cordova-plugin-touch-id',
pluginRef: 'plugins.touchid',
repo: 'https://github.com/EddyVerbruggen/cordova-plugin-touch-id'
})
export class TouchID {
2016-02-18 05:32:34 +08:00
/**
* Whether TouchID is available or not.
*
* @return {Promise} Returns a Promise that resolves if yes, rejects if no.
*/
2015-12-02 09:06:38 +08:00
@Cordova()
2016-02-18 05:32:34 +08:00
isAvailable() {
// This Promise is replaced by one from the @Cordova decorator that wraps
// the plugin's callbacks. We provide a dummy one here so TypeScript
// knows that the correct return type is Promise, because there's no way
// for it to know the return type from a decorator.
// See https://github.com/Microsoft/TypeScript/issues/4881
return new Promise<any>((res, rej) => {});
};
2015-12-02 09:06:38 +08:00
2016-02-18 05:32:34 +08:00
/**
* Show TouchID dialog and wait for a fingerprint scan. If user taps 'Enter Password' button, brings up standard system passcode screen.
*
* @param {string} message The message to display
* @return {Promise} Returns a Promise the resolves if the fingerprint scan was successful, rejects with an error code (see above).
*/
2015-12-02 09:06:38 +08:00
@Cordova()
2016-02-18 05:32:34 +08:00
static verifyFingerprint(message: string) {
// This Promise is replaced by one from the @Cordova decorator that wraps
// the plugin's callbacks. We provide a dummy one here so TypeScript
// knows that the correct return type is Promise, because there's no way
// for it to know the return type from a decorator.
// See https://github.com/Microsoft/TypeScript/issues/4881
return new Promise<any>((res, rej) => {});
}
2015-12-02 09:33:43 +08:00
2016-02-18 05:32:34 +08:00
/**
* Show TouchID dialog and wait for a fingerprint scan. If user taps 'Enter Password' button, rejects with code '-3' (see above).
*
* @param {string} message The message to display
* @return {Promise} Returns a Promise the resolves if the fingerprint scan was successful, rejects with an error code (see above).
*/
2015-12-02 09:33:43 +08:00
@Cordova()
2016-02-18 05:32:34 +08:00
static verifyFingerprintWithCustomPasswordFallback(message: string) {
// This Promise is replaced by one from the @Cordova decorator that wraps
// the plugin's callbacks. We provide a dummy one here so TypeScript
// knows that the correct return type is Promise, because there's no way
// for it to know the return type from a decorator.
// See https://github.com/Microsoft/TypeScript/issues/4881
return new Promise<any>((res, rej) => {});
}
2015-12-02 09:33:43 +08:00
2016-02-18 05:32:34 +08:00
/**
* Show TouchID dialog with custom 'Enter Password' message and wait for a fingerprint scan. If user taps 'Enter Password' button, rejects with code '-3' (see above).
*
* @param {string} message The message to display
* @param {string} enterPasswordLabel Custom text for the 'Enter Password' button
* @return {Promise} Returns a Promise the resolves if the fingerprint scan was successful, rejects with an error code (see above).
*/
2015-12-02 09:33:43 +08:00
@Cordova()
2016-02-18 05:32:34 +08:00
static verifyFingerprintWithCustomPasswordFallbackAndEnterPasswordLabel(message: string, enterPasswordLabel: string) {
// This Promise is replaced by one from the @Cordova decorator that wraps
// the plugin's callbacks. We provide a dummy one here so TypeScript
// knows that the correct return type is Promise, because there's no way
// for it to know the return type from a decorator.
// See https://github.com/Microsoft/TypeScript/issues/4881
return new Promise<any>((res, rej) => {});
}
2015-12-02 09:06:38 +08:00
}