Skip to content

Commit b8c29c9

Browse files
SandroMachadod-moreira
authored andcommitted
Add support for the release method on iOS
1 parent 9cecc0d commit b8c29c9

File tree

3 files changed

+46
-10
lines changed

3 files changed

+46
-10
lines changed

README.md

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

39-
3.0.2 and below:
39+
3.0.2 and below:
4040
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.
4141

4242
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
103103
<uses-permission android:name="android.permission.USE_BIOMETRIC" />
104104
```
105105

106-
API level 23-28 (Uses Android native FingerprintCompat) [Reference](https://developer.android.com/reference/android/Manifest.permission#USE_FINGERPRINT))
106+
API level 23-28 (Uses Android native FingerprintCompat) [Reference](https://developer.android.com/reference/android/Manifest.permission#USE_FINGERPRINT))
107107
```xml
108108
<uses-permission android:name="android.permission.USE_FINGERPRINT" />
109109
```
110110

111111
// DEPRECATED in 4.0.0
112-
API level <23 (Uses device-specific native fingerprinting, if available - Samsung & MeiZu only) [Reference](https://developer.android.com/reference/android/Manifest.permission#USE_FINGERPRINT))
112+
API level <23 (Uses device-specific native fingerprinting, if available - Samsung & MeiZu only) [Reference](https://developer.android.com/reference/android/Manifest.permission#USE_FINGERPRINT))
113113
```xml
114114
<uses-permission android:name="android.permission.USE_FINGERPRINT" />
115115
```
@@ -423,7 +423,7 @@ handleAuthenticationAttemptedLegacy = (error) => {
423423
};
424424
```
425425

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

429429
- Returns a `Void`
@@ -458,6 +458,7 @@ componentWillUnmount() {
458458
| DeviceLockedPermanent | Authentication was not successful, device must be unlocked via password |
459459
| DeviceOutOfMemory | Authentication could not proceed because there is not enough free memory on the device |
460460
| HardwareError | A hardware error occurred |
461+
| FingerprintScannerAppCancel | Scanner cancelled by the application |
461462
| FingerprintScannerUnknownError | Could not authenticate for an unknown reason |
462463
| FingerprintScannerNotSupported | Device does not support Fingerprint Scanner |
463464
| FingerprintScannerNotEnrolled | Authentication could not start because Fingerprint Scanner has no enrolled fingers |

ios/ReactNativeFingerprintScanner.m

Lines changed: 32 additions & 5 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]) {
@@ -57,7 +62,15 @@ @implementation ReactNativeFingerprintScanner
5762
fallback: (BOOL)fallbackEnabled
5863
callback: (RCTResponseSenderBlock)callback)
5964
{
60-
LAContext *context = [[LAContext alloc] init];
65+
if (context != nil) {
66+
[context invalidate];
67+
68+
return;
69+
}
70+
71+
context = [[LAContext alloc] init];
72+
73+
6174
NSError *error;
6275

6376
// Toggle fallback button
@@ -72,6 +85,8 @@ @implementation ReactNativeFingerprintScanner
7285
localizedReason:reason
7386
reply:^(BOOL success, NSError *error)
7487
{
88+
context = nil;
89+
7590
// Failed Authentication
7691
if (error) {
7792
NSString *errorReason;
@@ -105,9 +120,9 @@ @implementation ReactNativeFingerprintScanner
105120
errorReason = @"FingerprintScannerNotEnrolled";
106121
break;
107122

108-
case LAErrorBiometryLockout:
109-
errorReason = @"DeviceLockedPermanent";
110-
break;
123+
case LAErrorAppCancel:
124+
errorReason = @"FingerprintScannerAppCancel";
125+
break;
111126

112127
default:
113128
errorReason = @"FingerprintScannerUnknownError";
@@ -164,6 +179,17 @@ @implementation ReactNativeFingerprintScanner
164179
}
165180
}
166181

182+
RCT_EXPORT_METHOD(invalidate)
183+
{
184+
if (context == nil) {
185+
context = [[LAContext alloc] init];
186+
}
187+
188+
[context invalidate];
189+
190+
context = nil;
191+
}
192+
167193
- (NSString *)getBiometryType:(LAContext *)context
168194
{
169195
if (@available(iOS 11, *)) {
@@ -173,4 +199,5 @@ - (NSString *)getBiometryType:(LAContext *)context
173199
return @"Touch ID";
174200
}
175201

202+
176203
@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)