Skip to content

Commit 8db018a

Browse files
committed
Add support for the release method on iOS
1 parent 4a22b4d commit 8db018a

File tree

3 files changed

+47
-7
lines changed

3 files changed

+47
-7
lines changed

README.md

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ It provides a **Default View** that prompts the user to place a finger to the iP
2828
4.0.0 Prefers the new native Android BiometricPrompt lib on any Android >= v23 (M)
2929
4.0.0 also DEPRECATES support for the legacy library that provides support for Samsung & MeiZu phones
3030

31-
3.0.2 and below:
31+
3.0.2 and below:
3232
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.
3333

3434
Samsung and MeiZu's Fingerprint SDK supports most devices which system versions less than Android 6.0.
@@ -95,13 +95,13 @@ API level 28+ (Uses Android native BiometricPrompt) ([Reference](https://develop
9595
<uses-permission android:name="android.permission.USE_BIOMETRIC" />
9696
```
9797

98-
API level 23-28 (Uses Android native FingerprintCompat) [Reference](https://developer.android.com/reference/android/Manifest.permission#USE_FINGERPRINT))
98+
API level 23-28 (Uses Android native FingerprintCompat) [Reference](https://developer.android.com/reference/android/Manifest.permission#USE_FINGERPRINT))
9999
```xml
100100
<uses-permission android:name="android.permission.USE_FINGERPRINT" />
101101
```
102102

103103
// DEPRECATED in 4.0.0
104-
API level <23 (Uses device-specific native fingerprinting, if available - Samsung & MeiZu only) [Reference](https://developer.android.com/reference/android/Manifest.permission#USE_FINGERPRINT))
104+
API level <23 (Uses device-specific native fingerprinting, if available - Samsung & MeiZu only) [Reference](https://developer.android.com/reference/android/Manifest.permission#USE_FINGERPRINT))
105105
```xml
106106
<uses-permission android:name="android.permission.USE_FINGERPRINT" />
107107
```
@@ -412,7 +412,7 @@ handleAuthenticationAttemptedLegacy = (error) => {
412412
};
413413
```
414414

415-
### `release()`: (Android)
415+
### `release()`:
416416
Stops fingerprint scanner listener, releases cache of internal state in native code, and cancels native prompt if visible.
417417

418418
- Returns a `Void`
@@ -447,6 +447,7 @@ componentWillUnmount() {
447447
| DeviceLockedPermanent | Authentication was not successful, device must be unlocked via password |
448448
| DeviceOutOfMemory | Authentication could not proceed because there is not enough free memory on the device |
449449
| HardwareError | A hardware error occurred |
450+
| FingerprintScannerAppCancel | Scanner cancelled by the application |
450451
| FingerprintScannerUnknownError | Could not authenticate for an unknown reason |
451452
| FingerprintScannerNotSupported | Device does not support Fingerprint Scanner |
452453
| FingerprintScannerNotEnrolled | Authentication could not start because Fingerprint Scanner has no enrolled fingers |

ios/ReactNativeFingerprintScanner.m

Lines changed: 33 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,16 @@
88

99
@implementation ReactNativeFingerprintScanner
1010

11+
static LAContext *context = nil;
12+
1113
RCT_EXPORT_MODULE();
1214

1315
RCT_EXPORT_METHOD(isSensorAvailable: (RCTResponseSenderBlock)callback)
1416
{
15-
LAContext *context = [[LAContext alloc] init];
17+
if (context == nil) {
18+
context = [[LAContext alloc] init];
19+
}
20+
1621
NSError *error;
1722

1823
if ([context canEvaluatePolicy:LAPolicyDeviceOwnerAuthenticationWithBiometrics error:&error]) {
@@ -47,7 +52,15 @@ @implementation ReactNativeFingerprintScanner
4752
fallback: (BOOL)fallbackEnabled
4853
callback: (RCTResponseSenderBlock)callback)
4954
{
50-
LAContext *context = [[LAContext alloc] init];
55+
if (context != nil) {
56+
[context invalidate];
57+
58+
return;
59+
}
60+
61+
context = [[LAContext alloc] init];
62+
63+
5164
NSError *error;
5265

5366
// Toggle fallback button
@@ -62,6 +75,8 @@ @implementation ReactNativeFingerprintScanner
6275
localizedReason:reason
6376
reply:^(BOOL success, NSError *error)
6477
{
78+
context = nil;
79+
6580
// Failed Authentication
6681
if (error) {
6782
NSString *errorReason;
@@ -95,6 +110,10 @@ @implementation ReactNativeFingerprintScanner
95110
errorReason = @"FingerprintScannerNotEnrolled";
96111
break;
97112

113+
case LAErrorAppCancel:
114+
errorReason = @"FingerprintScannerAppCancel";
115+
break;
116+
98117
default:
99118
errorReason = @"FingerprintScannerUnknownError";
100119
break;
@@ -121,6 +140,17 @@ @implementation ReactNativeFingerprintScanner
121140
}
122141
}
123142

143+
RCT_EXPORT_METHOD(invalidate)
144+
{
145+
if (context == nil) {
146+
context = [[LAContext alloc] init];
147+
}
148+
149+
[context invalidate];
150+
151+
context = nil;
152+
}
153+
124154
- (NSString *)getBiometryType:(LAContext *)context
125155
{
126156
if (@available(iOS 11, *)) {
@@ -130,4 +160,5 @@ - (NSString *)getBiometryType:(LAContext *)context
130160
return @"Touch ID";
131161
}
132162

163+
133164
@end

src/release.ios.js

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,9 @@
1-
export default () => null;
1+
import { NativeModules } from 'react-native';
2+
3+
const { ReactNativeFingerprintScanner } = NativeModules;
4+
5+
export default () => {
6+
return new Promise(() => {
7+
ReactNativeFingerprintScanner.invalidate();
8+
});
9+
}

0 commit comments

Comments
 (0)