Skip to content

Commit 29d8cc0

Browse files
[local_auth] fix: isDeviceSupported on ios (flutter#5125)
Fixes: flutter/flutter#116179
1 parent 93ae4dd commit 29d8cc0

File tree

4 files changed

+27
-10
lines changed

4 files changed

+27
-10
lines changed

packages/local_auth/local_auth_ios/CHANGELOG.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
1-
## NEXT
1+
## 1.1.7
22

3+
* Implements `isDeviceSupported`.
34
* Updates minimum iOS version to 12.0 and minimum Flutter version to 3.16.6.
45

56
## 1.1.6

packages/local_auth/local_auth_ios/example/ios/RunnerTests/FLTLocalAuthPluginTests.m

Lines changed: 22 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -490,19 +490,36 @@ - (void)testGetEnrolledBiometricsWithoutEnrolledHardware {
490490
XCTAssertNil(error);
491491
}
492492

493-
// TODO(stuartmorgan): Make this multiple tests when fixing
494-
// https://github.com/flutter/flutter/issues/116179
495-
// Currently it just always returns true.
496-
- (void)testIsDeviceSupported {
493+
- (void)testIsDeviceSupportedHandlesSupported {
494+
id mockAuthContext = OCMClassMock([LAContext class]);
495+
OCMStub([mockAuthContext canEvaluatePolicy:LAPolicyDeviceOwnerAuthentication
496+
error:[OCMArg setTo:nil]])
497+
.andReturn(YES);
497498
FLTLocalAuthPlugin *plugin = [[FLTLocalAuthPlugin alloc]
498-
initWithContextFactory:[[StubAuthContextFactory alloc] initWithContexts:@[]]];
499+
initWithContextFactory:[[StubAuthContextFactory alloc]
500+
initWithContexts:@[ mockAuthContext ]]];
499501

500502
FlutterError *error;
501503
NSNumber *result = [plugin isDeviceSupportedWithError:&error];
502504
XCTAssertTrue([result boolValue]);
503505
XCTAssertNil(error);
504506
}
505507

508+
- (void)testIsDeviceSupportedHandlesUnsupported {
509+
id mockAuthContext = OCMClassMock([LAContext class]);
510+
OCMStub([mockAuthContext canEvaluatePolicy:LAPolicyDeviceOwnerAuthentication
511+
error:[OCMArg setTo:nil]])
512+
.andReturn(NO);
513+
FLTLocalAuthPlugin *plugin = [[FLTLocalAuthPlugin alloc]
514+
initWithContextFactory:[[StubAuthContextFactory alloc]
515+
initWithContexts:@[ mockAuthContext ]]];
516+
517+
FlutterError *error;
518+
NSNumber *result = [plugin isDeviceSupportedWithError:&error];
519+
XCTAssertFalse([result boolValue]);
520+
XCTAssertNil(error);
521+
}
522+
506523
// Creates an FLAAuthStrings with placeholder values.
507524
- (FLAAuthStrings *)createAuthStrings {
508525
return [FLAAuthStrings makeWithReason:@"a reason"

packages/local_auth/local_auth_ios/ios/Classes/FLTLocalAuthPlugin.m

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -146,9 +146,8 @@ - (nullable NSNumber *)deviceCanSupportBiometricsWithError:
146146

147147
- (nullable NSNumber *)isDeviceSupportedWithError:
148148
(FlutterError *_Nullable __autoreleasing *_Nonnull)error {
149-
// TODO(stuartmorgan): Fix this to check for biometrics or passcode; see
150-
// https://github.com/flutter/flutter/issues/116179
151-
return @YES;
149+
LAContext *context = [self.authContextFactory createAuthContext];
150+
return @([context canEvaluatePolicy:LAPolicyDeviceOwnerAuthentication error:NULL]);
152151
}
153152

154153
#pragma mark Private Methods

packages/local_auth/local_auth_ios/pubspec.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ name: local_auth_ios
22
description: iOS implementation of the local_auth plugin.
33
repository: https://github.com/flutter/packages/tree/main/packages/local_auth/local_auth_ios
44
issue_tracker: https://github.com/flutter/flutter/issues?q=is%3Aissue+is%3Aopen+label%3A%22p%3A+local_auth%22
5-
version: 1.1.6
5+
version: 1.1.7
66

77
environment:
88
sdk: ^3.2.3

0 commit comments

Comments
 (0)