From e926305cdaf686ce91b705799710019627237a3a Mon Sep 17 00:00:00 2001 From: Eugene Trusevich Date: Mon, 30 May 2022 11:27:36 +0300 Subject: [PATCH 1/2] fix(ios): mach_msg_trap and semaphore_wait_trap with camera or additional tasks --- package.json | 2 +- plugin.xml | 2 +- src/ios/Fingerprint.swift | 116 ++++++++++++++++++++++---------------- 3 files changed, 68 insertions(+), 52 deletions(-) diff --git a/package.json b/package.json index 4f50b5c..341fb8a 100644 --- a/package.json +++ b/package.json @@ -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", diff --git a/plugin.xml b/plugin.xml index be9d647..27de7c9 100644 --- a/plugin.xml +++ b/plugin.xml @@ -1,5 +1,5 @@ - + FingerprintAllInOne Cordova plugin to use fingerprint on Android and iOS MIT diff --git a/src/ios/Fingerprint.swift b/src/ios/Fingerprint.swift index 094e5b7..1523db6 100644 --- a/src/ios/Fingerprint.swift +++ b/src/ios/Fingerprint.swift @@ -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 { + 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) { From cf9fc3220d178e2aaf18d68e912fb52cfda1c432 Mon Sep 17 00:00:00 2001 From: Eugene Trusevich Date: Tue, 31 May 2022 10:46:31 +0300 Subject: [PATCH 2/2] fix(ios): weak self added --- src/ios/Fingerprint.swift | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/ios/Fingerprint.swift b/src/ios/Fingerprint.swift index 1523db6..17cf46d 100644 --- a/src/ios/Fingerprint.swift +++ b/src/ios/Fingerprint.swift @@ -36,7 +36,7 @@ enum PluginError:Int { @objc(isAvailable:) func isAvailable(_ command: CDVInvokedUrlCommand){ - performAsyncOnGlobal { + performAsyncOnGlobal { [weak self] in let authenticationContext = LAContext(); var biometryType = "finger"; var errorResponse: [AnyHashable: Any] = [ @@ -91,7 +91,7 @@ enum PluginError:Int { pluginResult = CDVPluginResult(status: CDVCommandStatus_ERROR, messageAs: results); } - self.commandDelegate.send(pluginResult, callbackId:command.callbackId); + self?.commandDelegate.send(pluginResult, callbackId:command.callbackId); } }