Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add didFingerprintDatabaseChange function #56

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions src/ios/TouchID.h
Original file line number Diff line number Diff line change
Expand Up @@ -35,5 +35,7 @@
- (void) verify:(CDVInvokedUrlCommand*)command;
- (void) delete:(CDVInvokedUrlCommand*)command;
- (void) setLocale:(CDVInvokedUrlCommand*)command;
- (void) didFingerprintDatabaseChange:(CDVInvokedUrlCommand*)command;


@end
41 changes: 41 additions & 0 deletions src/ios/TouchID.m
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ Licensed to the Apache Software Foundation (ASF) under one
#include <sys/sysctl.h>
#import <Cordova/CDV.h>

static NSString *const FingerprintDatabaseStateKey = @"FingerprintDatabaseStateKey";

@implementation TouchID

- (void)isAvailable:(CDVInvokedUrlCommand*)command{
Expand Down Expand Up @@ -166,4 +168,43 @@ -(void)verify:(CDVInvokedUrlCommand*)command{
[self.commandDelegate sendPluginResult:pluginResult callbackId:command.callbackId];
}
}

- (void) didFingerprintDatabaseChange:(CDVInvokedUrlCommand*)command {
// Get enrollment state
[self.commandDelegate runInBackground:^{
LAContext *laContext = [[LAContext alloc] init];
NSError *error = nil;

// we expect the dev to have checked 'isAvailable' already so this should not return an error,
// we do however need to run canEvaluatePolicy here in order to get a non-nil evaluatedPolicyDomainState
if (![laContext canEvaluatePolicy:LAPolicyDeviceOwnerAuthenticationWithBiometrics error:&error]) {
[self.commandDelegate sendPluginResult:[CDVPluginResult resultWithStatus:CDVCommandStatus_ERROR messageAsString:[error localizedDescription]] callbackId:command.callbackId];
return;
}

// only supported on iOS9+, so check this.. if not supported just report back as false
if (![laContext respondsToSelector:@selector(evaluatedPolicyDomainState)]) {
[self.commandDelegate sendPluginResult:[CDVPluginResult resultWithStatus:CDVCommandStatus_OK messageAsBool:NO] callbackId:command.callbackId];
return;
}

NSData * state = [laContext evaluatedPolicyDomainState];
if (state != nil) {

NSString * stateStr = [state base64EncodedStringWithOptions:0];

NSString * storedState = [[NSUserDefaults standardUserDefaults] stringForKey:FingerprintDatabaseStateKey];

// whenever a finger is added/changed/removed the value of the storedState changes,
// so compare agains a value we previously stored in the context of this app
BOOL changed = storedState != nil && ![stateStr isEqualToString:storedState];

[self.commandDelegate sendPluginResult:[CDVPluginResult resultWithStatus:CDVCommandStatus_OK messageAsBool:changed] callbackId:command.callbackId];

// Store enrollment
[[NSUserDefaults standardUserDefaults] setObject:stateStr forKey:FingerprintDatabaseStateKey];
[[NSUserDefaults standardUserDefaults] synchronize];
}
}];
}
@end
6 changes: 4 additions & 2 deletions www/touchid.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,10 @@ var touchid = {
},
move: function(key, packageName,successCallback, errorCallback){
exec(successCallback, errorCallback, "TouchID", "move", [key,packageName]);
}

},
didFingerprintDatabaseChange: function (successCallback, errorCallback) {
exec(successCallback, errorCallback, "TouchID", "didFingerprintDatabaseChange", []);
}
};

module.exports = touchid;