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

IOS: added 'Face id' or 'Touch id' detection support #36

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
8 changes: 4 additions & 4 deletions readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ if (window.plugins.touchid) {

Call the function you like

**isAvailable(successCallback, errorCallback(msg))** will Check if touchid is available on the used device
**isAvailable(successCallback(type), errorCallback(msg))** will Check if touchid is available on the used device and pass biometric type to success callback (`touch` or `face`)

**save(key,password, successCallback, errorCallback(msg))**
will save a password under the key in the device keychain, which can be retrieved using a fingerprint
Expand Down Expand Up @@ -92,11 +92,11 @@ This invalid key is removed - user needs to **save their password again**.

```js
if (window.plugins) {
window.plugins.touchid.isAvailable(function() {
window.plugins.touchid.isAvailable(function(type) {
window.plugins.touchid.has("MyKey", function() {
alert("Touch ID avaialble and Password key available");
alert(type + " ID avaialble and Password key available");
}, function() {
alert("Touch ID available but no Password Key available");
alert(type + " ID available but no Password Key available");
});
}, function(msg) {
alert("no Touch ID available");
Expand Down
36 changes: 26 additions & 10 deletions src/ios/TouchID.m
Original file line number Diff line number Diff line change
Expand Up @@ -24,17 +24,33 @@ Licensed to the Apache Software Foundation (ASF) under one

@implementation TouchID

- (void)isAvailable:(CDVInvokedUrlCommand*)command{
self.laContext = [[LAContext alloc] init];
BOOL touchIDAvailable = [self.laContext canEvaluatePolicy:LAPolicyDeviceOwnerAuthenticationWithBiometrics error:nil];
if(touchIDAvailable){
CDVPluginResult* pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK];
[self.commandDelegate sendPluginResult:pluginResult callbackId:command.callbackId];
}
else{
CDVPluginResult* pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_ERROR messageAsString: @"Touch ID not available"];
[self.commandDelegate sendPluginResult:pluginResult callbackId:command.callbackId];
- (void) isAvailable:(CDVInvokedUrlCommand*)command {

if (NSClassFromString(@"LAContext") == NULL) {
[self.commandDelegate sendPluginResult:[CDVPluginResult resultWithStatus:CDVCommandStatus_ERROR] callbackId:command.callbackId];
return;
}

[self.commandDelegate runInBackground:^{

NSError *error = nil;
LAContext *laContext = [[LAContext alloc] init];

if ([laContext canEvaluatePolicy:LAPolicyDeviceOwnerAuthenticationWithBiometrics error:&error]) {
NSString *biometryType = @"touch";
if (@available(iOS 11.0, *)) {
if (laContext.biometryType == LABiometryTypeFaceID) {
biometryType = @"face";
}
}
[self.commandDelegate sendPluginResult:[CDVPluginResult resultWithStatus:CDVCommandStatus_OK messageAsString:biometryType]
callbackId:command.callbackId];
} else {
NSArray *errorKeys = @[@"code", @"localizedDescription"];
[self.commandDelegate sendPluginResult:[CDVPluginResult resultWithStatus:CDVCommandStatus_ERROR messageAsDictionary:[error dictionaryWithValuesForKeys:errorKeys]]
callbackId:command.callbackId];
}
}];
}

- (void)setLocale:(CDVInvokedUrlCommand*)command{
Expand Down