diff options
| author | Arjun Roychowdhury <pliablepixels@gmail.com> | 2015-09-17 16:28:48 -0400 |
|---|---|---|
| committer | Arjun Roychowdhury <pliablepixels@gmail.com> | 2015-09-17 16:28:48 -0400 |
| commit | df19b39f1d8a4440b9c83fd297ea7d7748ca7cc9 (patch) | |
| tree | 9fac88b6f4e1177e179478ef9e9164f8405785f5 /plugins/cordova-plugin-touchid/src | |
| parent | 016b7e1190568149793f62fc6c1f268d46c06c49 (diff) | |
TouchID support now added for PIN
Diffstat (limited to 'plugins/cordova-plugin-touchid/src')
| -rw-r--r-- | plugins/cordova-plugin-touchid/src/ios/TouchID.h | 13 | ||||
| -rw-r--r-- | plugins/cordova-plugin-touchid/src/ios/TouchID.m | 79 |
2 files changed, 92 insertions, 0 deletions
diff --git a/plugins/cordova-plugin-touchid/src/ios/TouchID.h b/plugins/cordova-plugin-touchid/src/ios/TouchID.h new file mode 100644 index 00000000..d971a080 --- /dev/null +++ b/plugins/cordova-plugin-touchid/src/ios/TouchID.h @@ -0,0 +1,13 @@ +// +// TouchID.h +// Copyright (c) 2014 Lee Crossley - http://ilee.co.uk +// + +#import <Cordova/CDVPlugin.h> + +@interface TouchID : CDVPlugin + +- (void) authenticate:(CDVInvokedUrlCommand*)command; +- (void) checkSupport:(CDVInvokedUrlCommand*)command; + +@end diff --git a/plugins/cordova-plugin-touchid/src/ios/TouchID.m b/plugins/cordova-plugin-touchid/src/ios/TouchID.m new file mode 100644 index 00000000..0d39f7e2 --- /dev/null +++ b/plugins/cordova-plugin-touchid/src/ios/TouchID.m @@ -0,0 +1,79 @@ +// +// TouchID.m +// Copyright (c) 2014 Lee Crossley - http://ilee.co.uk +// + +#import "TouchID.h" + +#import <LocalAuthentication/LocalAuthentication.h> + +@implementation TouchID + +- (void) authenticate:(CDVInvokedUrlCommand*)command; +{ + NSString *text = [command.arguments objectAtIndex:0]; + + __block CDVPluginResult* pluginResult = nil; + + if (NSClassFromString(@"LAContext") != nil) + { + LAContext *laContext = [[LAContext alloc] init]; + NSError *authError = nil; + + if ([laContext canEvaluatePolicy:LAPolicyDeviceOwnerAuthenticationWithBiometrics error:&authError]) + { + [laContext evaluatePolicy:LAPolicyDeviceOwnerAuthenticationWithBiometrics localizedReason:text reply:^(BOOL success, NSError *error) + { + if (success) + { + pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK]; + } + else + { + pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_ERROR messageAsString:[error localizedDescription]]; + } + + [self.commandDelegate sendPluginResult:pluginResult callbackId:command.callbackId]; + }]; + } + else + { + pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_ERROR messageAsString:[authError localizedDescription]]; + [self.commandDelegate sendPluginResult:pluginResult callbackId:command.callbackId]; + } + } + else + { + pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_ERROR]; + [self.commandDelegate sendPluginResult:pluginResult callbackId:command.callbackId]; + } +} + +- (void) checkSupport:(CDVInvokedUrlCommand*)command; +{ + + __block CDVPluginResult* pluginResult = nil; + + if (NSClassFromString(@"LAContext") != nil) + { + LAContext *laContext = [[LAContext alloc] init]; + NSError *authError = nil; + + if ([laContext canEvaluatePolicy:LAPolicyDeviceOwnerAuthenticationWithBiometrics error:&authError]) + { + pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK]; + } + else + { + pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_ERROR messageAsString:[authError localizedDescription]]; + } + } + else + { + pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_ERROR]; + } + + [self.commandDelegate sendPluginResult:pluginResult callbackId:command.callbackId]; +} + +@end |
