Skip to content

Commit

Permalink
#6 Add the ability to override the 'Enter password' button label
Browse files Browse the repository at this point in the history
  • Loading branch information
EddyVerbruggen committed Nov 25, 2015
1 parent b1ddd20 commit 73f6a30
Show file tree
Hide file tree
Showing 8 changed files with 37 additions and 8 deletions.
14 changes: 13 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ Scan the fingerprint of your user with the TouchID sensor (iPhone 5S).
## 2. Screenshot
Distorted a bit because I created it back when Apple had not yet released the SDK and they're not a fan of developers posting screenshots of unreleased features.

![ScreenShot](TouchID-demo.png)
![ScreenShot](screenshots/TouchID-demo.PNG)

## 3. Installation

Expand Down Expand Up @@ -95,6 +95,18 @@ window.plugins.touchid.verifyFingerprintWithCustomPasswordFallback(
);
```

This will render a button labelled 'Enter password' in case the fingerprint is not recognized.
If you want to provide your own label ('Enter PIN' perhaps), you can use awkwardly named function (added in version 3.1.0):

```js
window.plugins.touchid.verifyFingerprintWithCustomPasswordFallbackAndEnterPasswordLabel(
'Scan your fingerprint please', // this will be shown in the native scanner popup
'Enter PIN', // this will become the 'Enter password' button label
function(msg) {alert('ok: ' + msg)}, // success handler: fingerprint accepted
function(msg) {alert('not ok: ' + JSON.stringify(msg))} // error handler with errorcode and localised reason
);
```

You can copy-paste these lines of code for a quick test:
```html
<button onclick="window.plugins.touchid.isAvailable(function(msg) {alert('ok: ' + msg)}, function(msg) {alert('not ok: ' + msg)})">Touch ID available?</button>
Expand Down
Binary file removed TouchID-demo.png
Binary file not shown.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "cordova-plugin-touch-id",
"version": "3.0.0",
"version": "3.1.0",
"description": "Scan the fingerprint of your user with the TouchID sensor (iPhone 5S, iPhone 6(S), ..)",
"cordova": {
"id": "cordova-plugin-touch-id",
Expand Down
2 changes: 1 addition & 1 deletion plugin.xml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<?xml version="1.0" encoding="UTF-8"?>
<plugin xmlns="http://apache.org/cordova/ns/plugins/1.0"
id="cordova-plugin-touch-id"
version="3.0.0">
version="3.1.0">

<name>Touch ID</name>

Expand Down
Binary file added screenshots/TouchID-demo.PNG
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 1 addition & 1 deletion src/ios/TouchID.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
- (void) isAvailable:(CDVInvokedUrlCommand*)command;

- (void) verifyFingerprint:(CDVInvokedUrlCommand*)command;

- (void) verifyFingerprintWithCustomPasswordFallback:(CDVInvokedUrlCommand*)command;
- (void) verifyFingerprintWithCustomPasswordFallbackAndEnterPasswordLabel:(CDVInvokedUrlCommand*)command;

@end
21 changes: 17 additions & 4 deletions src/ios/TouchID.m
Original file line number Diff line number Diff line change
Expand Up @@ -83,9 +83,17 @@ - (void) verifyFingerprint:(CDVInvokedUrlCommand*)command {

// This implementation uses LocalAuthentication and has no built-in passcode fallback
- (void) verifyFingerprintWithCustomPasswordFallback:(CDVInvokedUrlCommand*)command {

NSString *message = [command.arguments objectAtIndex:0];
NSString *callbackId = command.callbackId;
[self verifyFingerprintWithCustomPasswordFallback:command.callbackId withMessage:message andEnterPasswordLabel:nil];
}

- (void) verifyFingerprintWithCustomPasswordFallbackAndEnterPasswordLabel:(CDVInvokedUrlCommand*)command {
NSString *message = [command.arguments objectAtIndex:0];
NSString *enterPasswordLabel = [command.arguments objectAtIndex:1];
[self verifyFingerprintWithCustomPasswordFallback:command.callbackId withMessage:message andEnterPasswordLabel:enterPasswordLabel];
}

- (void) verifyFingerprintWithCustomPasswordFallback:(NSString*)callbackId withMessage:(NSString*)message andEnterPasswordLabel:(NSString*)enterPasswordLabel {

if (NSClassFromString(@"LAContext") == NULL) {
[self.commandDelegate sendPluginResult:[CDVPluginResult resultWithStatus:CDVCommandStatus_ERROR]
Expand All @@ -102,11 +110,16 @@ - (void) verifyFingerprintWithCustomPasswordFallback:(CDVInvokedUrlCommand*)comm
callbackId:callbackId];
return;
}


// this replaces the default 'Enter password' button label
if (enterPasswordLabel != nil) {
laContext.localizedFallbackTitle = enterPasswordLabel;
}

[laContext evaluatePolicy:LAPolicyDeviceOwnerAuthenticationWithBiometrics localizedReason:message reply:^(BOOL authOK, NSError *error) {
if (authOK) {
[self.commandDelegate sendPluginResult:[CDVPluginResult resultWithStatus:CDVCommandStatus_OK]
callbackId:command.callbackId];
callbackId:callbackId];
} else {
// invoked when the scan failed 3 times in a row, the cancel button was pressed, or the 'enter password' button was pressed
NSArray *errorKeys = @[@"code", @"localizedDescription"];
Expand Down
4 changes: 4 additions & 0 deletions www/TouchID.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,10 @@ TouchID.prototype.verifyFingerprintWithCustomPasswordFallback = function (messag
cordova.exec(successCallback, errorCallback, "TouchID", "verifyFingerprintWithCustomPasswordFallback", [message]);
};

TouchID.prototype.verifyFingerprintWithCustomPasswordFallbackAndEnterPasswordLabel = function (message, enterPasswordLabel, successCallback, errorCallback) {
cordova.exec(successCallback, errorCallback, "TouchID", "verifyFingerprintWithCustomPasswordFallbackAndEnterPasswordLabel", [message, enterPasswordLabel]);
};

TouchID.install = function () {
if (!window.plugins) {
window.plugins = {};
Expand Down

0 comments on commit 73f6a30

Please sign in to comment.