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

Run commands in threads #15

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
84 changes: 44 additions & 40 deletions src/ios/TouchID.m
Original file line number Diff line number Diff line change
Expand Up @@ -13,67 +13,71 @@ - (void) authenticate:(CDVInvokedUrlCommand*)command;
{
NSString *text = [command.arguments objectAtIndex:0];

__block CDVPluginResult* pluginResult = nil;
[self.commandDelegate runInBackground:^{
__block CDVPluginResult* pluginResult = nil;

if (NSClassFromString(@"LAContext") != nil)
{
LAContext *laContext = [[LAContext alloc] init];
NSError *authError = nil;

if ([laContext canEvaluatePolicy:LAPolicyDeviceOwnerAuthenticationWithBiometrics error:&authError])
if (NSClassFromString(@"LAContext") != nil)
{
[laContext evaluatePolicy:LAPolicyDeviceOwnerAuthenticationWithBiometrics localizedReason:text reply:^(BOOL success, NSError *error)
{
if (success)
{
pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK];
}
else
LAContext *laContext = [[LAContext alloc] init];
NSError *authError = nil;

if ([laContext canEvaluatePolicy:LAPolicyDeviceOwnerAuthenticationWithBiometrics error:&authError])
{
[laContext evaluatePolicy:LAPolicyDeviceOwnerAuthenticationWithBiometrics localizedReason:text reply:^(BOOL success, NSError *error)
{
pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_ERROR messageAsString:[error localizedDescription]];
}
if (success)
{
pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK];
}
else
{
pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_ERROR messageAsString:[error localizedDescription]];
}

[self.commandDelegate sendPluginResult:pluginResult callbackId:command.callbackId];
}];
[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 messageAsString:[authError localizedDescription]];
pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_ERROR];
[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;
[self.commandDelegate runInBackground:^{
__block CDVPluginResult* pluginResult = nil;

if (NSClassFromString(@"LAContext") != nil)
{
LAContext *laContext = [[LAContext alloc] init];
NSError *authError = nil;

if ([laContext canEvaluatePolicy:LAPolicyDeviceOwnerAuthenticationWithBiometrics error:&authError])
if (NSClassFromString(@"LAContext") != nil)
{
pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK];
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 messageAsString:[authError localizedDescription]];
pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_ERROR];
}
}
else
{
pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_ERROR];
}

[self.commandDelegate sendPluginResult:pluginResult callbackId:command.callbackId];
[self.commandDelegate sendPluginResult:pluginResult callbackId:command.callbackId];
}];
}

@end