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

fix(ios): mach_msg_trap and semaphore_wait_trap with camera or additi… #424

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: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "cordova-plugin-fingerprint-aio",
"version": "5.0.1",
"version": "5.0.1-dev",
"description": "Cordova plugin to use fingerprint authentication on Android and iOS",
"cordova": {
"id": "cordova-plugin-fingerprint-aio",
Expand Down
2 changes: 1 addition & 1 deletion plugin.xml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<?xml version="1.0" encoding="UTF-8"?>
<plugin xmlns="http://apache.org/cordova/ns/plugins/1.0" xmlns:android="http://schemas.android.com/apk/res/android" id="cordova-plugin-fingerprint-aio" version="5.0.1">
<plugin xmlns="http://apache.org/cordova/ns/plugins/1.0" xmlns:android="http://schemas.android.com/apk/res/android" id="cordova-plugin-fingerprint-aio" version="5.0.1-dev">
<name>FingerprintAllInOne</name>
<description>Cordova plugin to use fingerprint on Android and iOS</description>
<license>MIT</license>
Expand Down
116 changes: 66 additions & 50 deletions src/ios/Fingerprint.swift
Original file line number Diff line number Diff line change
Expand Up @@ -19,64 +19,80 @@ enum PluginError:Int {
var code: Int
}

// func performSyncOnMain(_ block: () -> Void) {
// if Thread.isMainThread {
// block()
// } else {
// DispatchQueue.main.sync(execute: block)
// }
// }

func performAsyncOnGlobal(_execure: @escaping (() -> Void)) {
DispatchQueue.global().async {
_execure()
}
}


@objc(isAvailable:)
func isAvailable(_ command: CDVInvokedUrlCommand){
let authenticationContext = LAContext();
var biometryType = "finger";
var errorResponse: [AnyHashable: Any] = [
"code": 0,
"message": "Not Available"
];
var error:NSError?;
let params = command.argument(at: 0) as? [AnyHashable: Any] ?? [:]
let allowBackup = params["allowBackup"] as? Bool ?? false
let policy:LAPolicy = allowBackup ? .deviceOwnerAuthentication : .deviceOwnerAuthenticationWithBiometrics;
var pluginResult = CDVPluginResult(status: CDVCommandStatus_ERROR, messageAs: "Not available");
let available = authenticationContext.canEvaluatePolicy(policy, error: &error);

var results: [String : Any]

if(error != nil){
biometryType = "none";
errorResponse["code"] = error?.code;
errorResponse["message"] = error?.localizedDescription;
}
performAsyncOnGlobal { [weak self] in
let authenticationContext = LAContext();
var biometryType = "finger";
var errorResponse: [AnyHashable: Any] = [
"code": 0,
"message": "Not Available"
];
var error:NSError?;
let params = command.argument(at: 0) as? [AnyHashable: Any] ?? [:]
let allowBackup = params["allowBackup"] as? Bool ?? false
let policy:LAPolicy = allowBackup ? .deviceOwnerAuthentication : .deviceOwnerAuthenticationWithBiometrics;
var pluginResult = CDVPluginResult(status: CDVCommandStatus_ERROR, messageAs: "Not available");
let available = authenticationContext.canEvaluatePolicy(policy, error: &error);

var results: [String : Any]

if(error != nil){
biometryType = "none";
errorResponse["code"] = error?.code;
errorResponse["message"] = error?.localizedDescription;
}

if (available == true) {
if #available(iOS 11.0, *) {
switch(authenticationContext.biometryType) {
case .none:
biometryType = "none";
case .touchID:
biometryType = "finger";
case .faceID:
biometryType = "face"
@unknown default:
errorResponse["message"] = "Unkown biometry type"
if (available == true) {
if #available(iOS 11.0, *) {
switch(authenticationContext.biometryType) {
case .none:
biometryType = "none";
case .touchID:
biometryType = "finger";
case .faceID:
biometryType = "face"
@unknown default:
errorResponse["message"] = "Unkown biometry type"
}
}
}

pluginResult = CDVPluginResult(status: CDVCommandStatus_OK, messageAs: biometryType);
}else{
var code: Int;
switch(error!._code) {
case Int(kLAErrorBiometryNotAvailable):
code = PluginError.BIOMETRIC_UNAVAILABLE.rawValue;
break;
case Int(kLAErrorBiometryNotEnrolled):
code = PluginError.BIOMETRIC_NOT_ENROLLED.rawValue;
break;

default:
code = PluginError.BIOMETRIC_UNKNOWN_ERROR.rawValue;
break;
pluginResult = CDVPluginResult(status: CDVCommandStatus_OK, messageAs: biometryType);
}else{
var code: Int;
switch(error!._code) {
case Int(kLAErrorBiometryNotAvailable):
code = PluginError.BIOMETRIC_UNAVAILABLE.rawValue;
break;
case Int(kLAErrorBiometryNotEnrolled):
code = PluginError.BIOMETRIC_NOT_ENROLLED.rawValue;
break;

default:
code = PluginError.BIOMETRIC_UNKNOWN_ERROR.rawValue;
break;
}
results = ["code": code, "message": error!.localizedDescription];
pluginResult = CDVPluginResult(status: CDVCommandStatus_ERROR, messageAs: results);
}
results = ["code": code, "message": error!.localizedDescription];
pluginResult = CDVPluginResult(status: CDVCommandStatus_ERROR, messageAs: results);
}

commandDelegate.send(pluginResult, callbackId:command.callbackId);
self?.commandDelegate.send(pluginResult, callbackId:command.callbackId);
}
}

func justAuthenticate(_ command: CDVInvokedUrlCommand) {
Expand Down