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

Add support for the release method on iOS #121

Open
wants to merge 1 commit 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
9 changes: 5 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -103,13 +103,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 @@ -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`
Expand Down Expand Up @@ -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 |
Expand Down
37 changes: 32 additions & 5 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 @@ -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
Expand All @@ -72,6 +85,8 @@ @implementation ReactNativeFingerprintScanner
localizedReason:reason
reply:^(BOOL success, NSError *error)
{
context = nil;

// Failed Authentication
if (error) {
NSString *errorReason;
Expand Down Expand Up @@ -105,9 +120,9 @@ @implementation ReactNativeFingerprintScanner
errorReason = @"FingerprintScannerNotEnrolled";
break;

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

default:
errorReason = @"FingerprintScannerUnknownError";
Expand Down Expand Up @@ -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, *)) {
Expand All @@ -173,4 +199,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();
});
}