Skip to content

Commit 85e7e10

Browse files
[local_auth] Migrate iOS to Pigeon (#3974)
Updates the platform communication to use Pigeon. This includes some changes to the API boundary: - Collected authentication options into an options object; this avoids having a lot of positional boolean arguments (since Pigeon doesn't currently support named arguments). - Collected strings into a strings object, since having them as individual parameters would have been extremely messy. - Changes the `authenticate` return from a bool+exceptions to an enum that encompasses all of the explicitly known failure modes. To avoid a breaking change for clients, the Dart code creates `PlatformException`s that match the old ones, but this will make it much easier to someday make a (cross-platform) breaking change to replace them with better errors per the best practices we have documented on the wiki. Using an enum rather than throwing errors avoids the need to do string matching when we want to eventually translate them into something other than `PlatformException`. The Pigeon file, Dart implementation, and rewritten tests are all based very heavily on the recent Android migration: #3748 I noted several bugs that I noticed in the existing implementation during the migration. I intentionally didn't fix them so this isn't changing behavior at the same time that it's changing so much of the code and tests, but I marked them with TODO comments. Fixes flutter/flutter#117912
1 parent 1dea5f9 commit 85e7e10

File tree

14 files changed

+1723
-570
lines changed

14 files changed

+1723
-570
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.3
22

3+
* Migrates internal implementation to Pigeon.
34
* Updates minimum supported SDK version to Flutter 3.3/Dart 2.18.
45

56
## 1.1.2

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

Lines changed: 162 additions & 193 deletions
Large diffs are not rendered by default.

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

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,5 +4,7 @@
44

55
#import <Flutter/Flutter.h>
66

7-
@interface FLTLocalAuthPlugin : NSObject <FlutterPlugin>
7+
#import "messages.g.h"
8+
9+
@interface FLTLocalAuthPlugin : NSObject <FlutterPlugin, FLALocalAuthApi>
810
@end

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

Lines changed: 150 additions & 143 deletions
Large diffs are not rendered by default.
Lines changed: 123 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,123 @@
1+
// Copyright 2013 The Flutter Authors. All rights reserved.
2+
// Use of this source code is governed by a BSD-style license that can be
3+
// found in the LICENSE file.
4+
// Autogenerated from Pigeon (v9.2.5), do not edit directly.
5+
// See also: https://pub.dev/packages/pigeon
6+
7+
#import <Foundation/Foundation.h>
8+
9+
@protocol FlutterBinaryMessenger;
10+
@protocol FlutterMessageCodec;
11+
@class FlutterError;
12+
@class FlutterStandardTypedData;
13+
14+
NS_ASSUME_NONNULL_BEGIN
15+
16+
/// Possible outcomes of an authentication attempt.
17+
typedef NS_ENUM(NSUInteger, FLAAuthResult) {
18+
/// The user authenticated successfully.
19+
FLAAuthResultSuccess = 0,
20+
/// The user failed to successfully authenticate.
21+
FLAAuthResultFailure = 1,
22+
/// The authentication system was not available.
23+
FLAAuthResultErrorNotAvailable = 2,
24+
/// No biometrics are enrolled.
25+
FLAAuthResultErrorNotEnrolled = 3,
26+
/// No passcode is set.
27+
FLAAuthResultErrorPasscodeNotSet = 4,
28+
};
29+
30+
/// Pigeon equivalent of the subset of BiometricType used by iOS.
31+
typedef NS_ENUM(NSUInteger, FLAAuthBiometric) {
32+
FLAAuthBiometricFace = 0,
33+
FLAAuthBiometricFingerprint = 1,
34+
};
35+
36+
@class FLAAuthStrings;
37+
@class FLAAuthOptions;
38+
@class FLAAuthResultDetails;
39+
@class FLAAuthBiometricWrapper;
40+
41+
/// Pigeon version of IOSAuthMessages, plus the authorization reason.
42+
///
43+
/// See auth_messages_ios.dart for details.
44+
@interface FLAAuthStrings : NSObject
45+
/// `init` unavailable to enforce nonnull fields, see the `make` class method.
46+
- (instancetype)init NS_UNAVAILABLE;
47+
+ (instancetype)makeWithReason:(NSString *)reason
48+
lockOut:(NSString *)lockOut
49+
goToSettingsButton:(NSString *)goToSettingsButton
50+
goToSettingsDescription:(NSString *)goToSettingsDescription
51+
cancelButton:(NSString *)cancelButton
52+
localizedFallbackTitle:(nullable NSString *)localizedFallbackTitle;
53+
@property(nonatomic, copy) NSString *reason;
54+
@property(nonatomic, copy) NSString *lockOut;
55+
@property(nonatomic, copy) NSString *goToSettingsButton;
56+
@property(nonatomic, copy) NSString *goToSettingsDescription;
57+
@property(nonatomic, copy) NSString *cancelButton;
58+
@property(nonatomic, copy, nullable) NSString *localizedFallbackTitle;
59+
@end
60+
61+
@interface FLAAuthOptions : NSObject
62+
/// `init` unavailable to enforce nonnull fields, see the `make` class method.
63+
- (instancetype)init NS_UNAVAILABLE;
64+
+ (instancetype)makeWithBiometricOnly:(NSNumber *)biometricOnly
65+
sticky:(NSNumber *)sticky
66+
useErrorDialogs:(NSNumber *)useErrorDialogs;
67+
@property(nonatomic, strong) NSNumber *biometricOnly;
68+
@property(nonatomic, strong) NSNumber *sticky;
69+
@property(nonatomic, strong) NSNumber *useErrorDialogs;
70+
@end
71+
72+
@interface FLAAuthResultDetails : NSObject
73+
/// `init` unavailable to enforce nonnull fields, see the `make` class method.
74+
- (instancetype)init NS_UNAVAILABLE;
75+
+ (instancetype)makeWithResult:(FLAAuthResult)result
76+
errorMessage:(nullable NSString *)errorMessage
77+
errorDetails:(nullable NSString *)errorDetails;
78+
/// The result of authenticating.
79+
@property(nonatomic, assign) FLAAuthResult result;
80+
/// A system-provided error message, if any.
81+
@property(nonatomic, copy, nullable) NSString *errorMessage;
82+
/// System-provided error details, if any.
83+
@property(nonatomic, copy, nullable) NSString *errorDetails;
84+
@end
85+
86+
@interface FLAAuthBiometricWrapper : NSObject
87+
/// `init` unavailable to enforce nonnull fields, see the `make` class method.
88+
- (instancetype)init NS_UNAVAILABLE;
89+
+ (instancetype)makeWithValue:(FLAAuthBiometric)value;
90+
@property(nonatomic, assign) FLAAuthBiometric value;
91+
@end
92+
93+
/// The codec used by FLALocalAuthApi.
94+
NSObject<FlutterMessageCodec> *FLALocalAuthApiGetCodec(void);
95+
96+
@protocol FLALocalAuthApi
97+
/// Returns true if this device supports authentication.
98+
///
99+
/// @return `nil` only when `error != nil`.
100+
- (nullable NSNumber *)isDeviceSupportedWithError:(FlutterError *_Nullable *_Nonnull)error;
101+
/// Returns true if this device can support biometric authentication, whether
102+
/// any biometrics are enrolled or not.
103+
///
104+
/// @return `nil` only when `error != nil`.
105+
- (nullable NSNumber *)deviceCanSupportBiometricsWithError:(FlutterError *_Nullable *_Nonnull)error;
106+
/// Returns the biometric types that are enrolled, and can thus be used
107+
/// without additional setup.
108+
///
109+
/// @return `nil` only when `error != nil`.
110+
- (nullable NSArray<FLAAuthBiometricWrapper *> *)getEnrolledBiometricsWithError:
111+
(FlutterError *_Nullable *_Nonnull)error;
112+
/// Attempts to authenticate the user with the provided [options], and using
113+
/// [strings] for any UI.
114+
- (void)authenticateWithOptions:(FLAAuthOptions *)options
115+
strings:(FLAAuthStrings *)strings
116+
completion:(void (^)(FLAAuthResultDetails *_Nullable,
117+
FlutterError *_Nullable))completion;
118+
@end
119+
120+
extern void FLALocalAuthApiSetup(id<FlutterBinaryMessenger> binaryMessenger,
121+
NSObject<FLALocalAuthApi> *_Nullable api);
122+
123+
NS_ASSUME_NONNULL_END

0 commit comments

Comments
 (0)