Skip to content

Commit

Permalink
Add support for the release method on iOS
Browse files Browse the repository at this point in the history
  • Loading branch information
SandroMachado committed Feb 5, 2020
1 parent 4a22b4d commit 8db018a
Show file tree
Hide file tree
Showing 3 changed files with 47 additions and 7 deletions.
9 changes: 5 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,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.
Expand Down Expand Up @@ -95,13 +95,13 @@ API level 28+ (Uses Android native BiometricPrompt) ([Reference](https://develop
<uses-permission android:name="android.permission.USE_BIOMETRIC" />
```

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
<uses-permission android:name="android.permission.USE_FINGERPRINT" />
```

// 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
<uses-permission android:name="android.permission.USE_FINGERPRINT" />
```
Expand Down Expand Up @@ -412,7 +412,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`
Expand Down Expand Up @@ -447,6 +447,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 |
Expand Down
35 changes: 33 additions & 2 deletions ios/ReactNativeFingerprintScanner.m
Original file line number Diff line number Diff line change
Expand Up @@ -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]) {
Expand Down Expand Up @@ -47,7 +52,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
Expand All @@ -62,6 +75,8 @@ @implementation ReactNativeFingerprintScanner
localizedReason:reason
reply:^(BOOL success, NSError *error)
{
context = nil;

// Failed Authentication
if (error) {
NSString *errorReason;
Expand Down Expand Up @@ -95,6 +110,10 @@ @implementation ReactNativeFingerprintScanner
errorReason = @"FingerprintScannerNotEnrolled";
break;

case LAErrorAppCancel:
errorReason = @"FingerprintScannerAppCancel";
break;

default:
errorReason = @"FingerprintScannerUnknownError";
break;
Expand All @@ -121,6 +140,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, *)) {
Expand All @@ -130,4 +160,5 @@ - (NSString *)getBiometryType:(LAContext *)context
return @"Touch ID";
}


@end
10 changes: 9 additions & 1 deletion src/release.ios.js
Original file line number Diff line number Diff line change
@@ -1 +1,9 @@
export default () => null;
import { NativeModules } from 'react-native';

const { ReactNativeFingerprintScanner } = NativeModules;

export default () => {
return new Promise(() => {
ReactNativeFingerprintScanner.invalidate();
});
}

0 comments on commit 8db018a

Please sign in to comment.