diff --git a/README.md b/README.md index de9d646d..e984beef 100644 --- a/README.md +++ b/README.md @@ -36,7 +36,7 @@ It provides a **Default View** that prompts the user to place a finger to the iP 4.0.0 Prefers the new native Android BiometricPrompt lib on any Android >= v23 (M) 4.0.0 also DEPRECATES support for the legacy library that provides support for Samsung & MeiZu phones -3.0.2 and below: +3.0.2 and below: Using an expandable Android Fingerprint API library, which combines [Samsung](http://developer.samsung.com/galaxy/pass#) and [MeiZu](http://open-wiki.flyme.cn/index.php?title=%E6%8C%87%E7%BA%B9%E8%AF%86%E5%88%ABAPI)'s official Fingerprint API. Samsung and MeiZu's Fingerprint SDK supports most devices which system versions less than Android 6.0. @@ -103,13 +103,13 @@ API level 28+ (Uses Android native BiometricPrompt) ([Reference](https://develop ``` -API level 23-28 (Uses Android native FingerprintCompat) [Reference](https://developer.android.com/reference/android/Manifest.permission#USE_FINGERPRINT)) +API level 23-28 (Uses Android native FingerprintCompat) [Reference](https://developer.android.com/reference/android/Manifest.permission#USE_FINGERPRINT)) ```xml ``` // DEPRECATED in 4.0.0 -API level <23 (Uses device-specific native fingerprinting, if available - Samsung & MeiZu only) [Reference](https://developer.android.com/reference/android/Manifest.permission#USE_FINGERPRINT)) +API level <23 (Uses device-specific native fingerprinting, if available - Samsung & MeiZu only) [Reference](https://developer.android.com/reference/android/Manifest.permission#USE_FINGERPRINT)) ```xml ``` @@ -423,7 +423,7 @@ handleAuthenticationAttemptedLegacy = (error) => { }; ``` -### `release()`: (Android) +### `release()`: Stops fingerprint scanner listener, releases cache of internal state in native code, and cancels native prompt if visible. - Returns a `Void` @@ -458,6 +458,7 @@ componentWillUnmount() { | DeviceLockedPermanent | Authentication was not successful, device must be unlocked via password | | DeviceOutOfMemory | Authentication could not proceed because there is not enough free memory on the device | | HardwareError | A hardware error occurred | +| FingerprintScannerAppCancel | Scanner cancelled by the application | | FingerprintScannerUnknownError | Could not authenticate for an unknown reason | | FingerprintScannerNotSupported | Device does not support Fingerprint Scanner | | FingerprintScannerNotEnrolled | Authentication could not start because Fingerprint Scanner has no enrolled fingers | diff --git a/ios/ReactNativeFingerprintScanner.m b/ios/ReactNativeFingerprintScanner.m index e29bad72..67be9a37 100644 --- a/ios/ReactNativeFingerprintScanner.m +++ b/ios/ReactNativeFingerprintScanner.m @@ -8,11 +8,16 @@ @implementation ReactNativeFingerprintScanner +static LAContext *context = nil; + RCT_EXPORT_MODULE(); RCT_EXPORT_METHOD(isSensorAvailable: (RCTResponseSenderBlock)callback) { - LAContext *context = [[LAContext alloc] init]; + if (context == nil) { + context = [[LAContext alloc] init]; + } + NSError *error; if ([context canEvaluatePolicy:LAPolicyDeviceOwnerAuthenticationWithBiometrics error:&error]) { @@ -57,7 +62,15 @@ @implementation ReactNativeFingerprintScanner fallback: (BOOL)fallbackEnabled callback: (RCTResponseSenderBlock)callback) { - LAContext *context = [[LAContext alloc] init]; + if (context != nil) { + [context invalidate]; + + return; + } + + context = [[LAContext alloc] init]; + + NSError *error; // Toggle fallback button @@ -72,6 +85,8 @@ @implementation ReactNativeFingerprintScanner localizedReason:reason reply:^(BOOL success, NSError *error) { + context = nil; + // Failed Authentication if (error) { NSString *errorReason; @@ -105,9 +120,9 @@ @implementation ReactNativeFingerprintScanner errorReason = @"FingerprintScannerNotEnrolled"; break; - case LAErrorBiometryLockout: - errorReason = @"DeviceLockedPermanent"; - break; + case LAErrorAppCancel: + errorReason = @"FingerprintScannerAppCancel"; + break; default: errorReason = @"FingerprintScannerUnknownError"; @@ -164,6 +179,17 @@ @implementation ReactNativeFingerprintScanner } } +RCT_EXPORT_METHOD(invalidate) +{ + if (context == nil) { + context = [[LAContext alloc] init]; + } + + [context invalidate]; + + context = nil; +} + - (NSString *)getBiometryType:(LAContext *)context { if (@available(iOS 11, *)) { @@ -173,4 +199,5 @@ - (NSString *)getBiometryType:(LAContext *)context return @"Touch ID"; } + @end diff --git a/src/release.ios.js b/src/release.ios.js index 461f67a0..020b8489 100644 --- a/src/release.ios.js +++ b/src/release.ios.js @@ -1 +1,9 @@ -export default () => null; +import { NativeModules } from 'react-native'; + +const { ReactNativeFingerprintScanner } = NativeModules; + +export default () => { + return new Promise(() => { + ReactNativeFingerprintScanner.invalidate(); + }); +}