1
1
// Copyright 2013 The Flutter Authors. All rights reserved.
2
2
// Use of this source code is governed by a BSD-style license that can be
3
3
// found in the LICENSE file.
4
- #import " FLTLocalAuthPlugin .h"
5
- #import " FLTLocalAuthPlugin_Test .h"
4
+ #import " FLALocalAuthPlugin .h"
5
+ #import " FLALocalAuthPlugin_Test .h"
6
6
7
7
#import < LocalAuthentication/LocalAuthentication.h>
8
8
9
- typedef void (^FLAAuthCompletion)(FLAAuthResultDetails *_Nullable, FlutterError *_Nullable);
9
+ typedef void (^FLADAuthCompletion)(FLADAuthResultDetails *_Nullable, FlutterError *_Nullable);
10
10
11
11
/* *
12
12
* A default context factory that wraps standard LAContext allocation.
13
13
*/
14
- @interface FLADefaultAuthContextFactory : NSObject <FLAAuthContextFactory >
14
+ @interface FLADefaultAuthContextFactory : NSObject <FLADAuthContextFactory >
15
15
@end
16
16
17
17
@implementation FLADefaultAuthContextFactory
@@ -26,18 +26,18 @@ - (LAContext *)createAuthContext {
26
26
* A data container for sticky auth state.
27
27
*/
28
28
@interface FLAStickyAuthState : NSObject
29
- @property (nonatomic , strong , nonnull ) FLAAuthOptions *options;
30
- @property (nonatomic , strong , nonnull ) FLAAuthStrings *strings;
31
- @property (nonatomic , copy , nonnull ) FLAAuthCompletion resultHandler;
32
- - (instancetype )initWithOptions : (nonnull FLAAuthOptions *)options
33
- strings : (nonnull FLAAuthStrings *)strings
34
- resultHandler : (nonnull FLAAuthCompletion )resultHandler ;
29
+ @property (nonatomic , strong , nonnull ) FLADAuthOptions *options;
30
+ @property (nonatomic , strong , nonnull ) FLADAuthStrings *strings;
31
+ @property (nonatomic , copy , nonnull ) FLADAuthCompletion resultHandler;
32
+ - (instancetype )initWithOptions : (nonnull FLADAuthOptions *)options
33
+ strings : (nonnull FLADAuthStrings *)strings
34
+ resultHandler : (nonnull FLADAuthCompletion )resultHandler ;
35
35
@end
36
36
37
37
@implementation FLAStickyAuthState
38
- - (instancetype )initWithOptions : (nonnull FLAAuthOptions *)options
39
- strings : (nonnull FLAAuthStrings *)strings
40
- resultHandler : (nonnull FLAAuthCompletion )resultHandler {
38
+ - (instancetype )initWithOptions : (nonnull FLADAuthOptions *)options
39
+ strings : (nonnull FLADAuthStrings *)strings
40
+ resultHandler : (nonnull FLADAuthCompletion )resultHandler {
41
41
self = [super init ];
42
42
if (self) {
43
43
_options = options;
@@ -50,36 +50,36 @@ - (instancetype)initWithOptions:(nonnull FLAAuthOptions *)options
50
50
51
51
#pragma mark -
52
52
53
- @interface FLTLocalAuthPlugin ()
53
+ @interface FLALocalAuthPlugin ()
54
54
@property (nonatomic , strong , nullable ) FLAStickyAuthState *lastCallState;
55
- @property (nonatomic , strong ) NSObject <FLAAuthContextFactory > *authContextFactory;
55
+ @property (nonatomic , strong ) NSObject <FLADAuthContextFactory > *authContextFactory;
56
56
@end
57
57
58
- @implementation FLTLocalAuthPlugin
58
+ @implementation FLALocalAuthPlugin
59
59
60
60
+ (void )registerWithRegistrar : (NSObject <FlutterPluginRegistrar> *)registrar {
61
- FLTLocalAuthPlugin *instance = [[FLTLocalAuthPlugin alloc ] init ];
61
+ FLALocalAuthPlugin *instance = [[FLALocalAuthPlugin alloc ] init ];
62
62
[registrar addApplicationDelegate: instance];
63
- SetUpFLALocalAuthApi ([registrar messenger ], instance);
63
+ SetUpFLADLocalAuthApi ([registrar messenger ], instance);
64
64
}
65
65
66
66
- (instancetype )init {
67
67
return [self initWithContextFactory: [[FLADefaultAuthContextFactory alloc ] init ]];
68
68
}
69
69
70
- - (instancetype )initWithContextFactory : (NSObject <FLAAuthContextFactory > *)factory {
70
+ - (instancetype )initWithContextFactory : (NSObject <FLADAuthContextFactory > *)factory {
71
71
self = [super init ];
72
72
if (self) {
73
73
_authContextFactory = factory;
74
74
}
75
75
return self;
76
76
}
77
77
78
- #pragma mark FLALocalAuthApi
78
+ #pragma mark FLADLocalAuthApi
79
79
80
- - (void )authenticateWithOptions : (nonnull FLAAuthOptions *)options
81
- strings : (nonnull FLAAuthStrings *)strings
82
- completion : (nonnull void (^)(FLAAuthResultDetails *_Nullable,
80
+ - (void )authenticateWithOptions : (nonnull FLADAuthOptions *)options
81
+ strings : (nonnull FLADAuthStrings *)strings
82
+ completion : (nonnull void (^)(FLADAuthResultDetails *_Nullable,
83
83
FlutterError *_Nullable))completion {
84
84
LAContext *context = [self .authContextFactory createAuthContext ];
85
85
NSError *authError = nil ;
@@ -126,18 +126,19 @@ - (nullable NSNumber *)deviceCanSupportBiometricsWithError:
126
126
return @NO ;
127
127
}
128
128
129
- - (nullable NSArray <FLAAuthBiometricWrapper *> *)getEnrolledBiometricsWithError :
129
+ - (nullable NSArray <FLADAuthBiometricWrapper *> *)getEnrolledBiometricsWithError :
130
130
(FlutterError *_Nullable __autoreleasing *_Nonnull)error {
131
131
LAContext *context = [self .authContextFactory createAuthContext ];
132
132
NSError *authError = nil ;
133
- NSMutableArray <FLAAuthBiometricWrapper *> *biometrics = [[NSMutableArray alloc ] init ];
133
+ NSMutableArray <FLADAuthBiometricWrapper *> *biometrics = [[NSMutableArray alloc ] init ];
134
134
if ([context canEvaluatePolicy: LAPolicyDeviceOwnerAuthenticationWithBiometrics
135
135
error: &authError]) {
136
136
if (authError == nil ) {
137
137
if (context.biometryType == LABiometryTypeFaceID) {
138
- [biometrics addObject: [FLAAuthBiometricWrapper makeWithValue: FLAAuthBiometricFace ]];
138
+ [biometrics addObject: [FLADAuthBiometricWrapper makeWithValue: FLADAuthBiometricFace ]];
139
139
} else if (context.biometryType == LABiometryTypeTouchID) {
140
- [biometrics addObject: [FLAAuthBiometricWrapper makeWithValue: FLAAuthBiometricFingerprint]];
140
+ [biometrics
141
+ addObject: [FLADAuthBiometricWrapper makeWithValue: FLADAuthBiometricFingerprint]];
141
142
}
142
143
}
143
144
}
@@ -155,7 +156,7 @@ - (nullable NSNumber *)isDeviceSupportedWithError:
155
156
- (void )showAlertWithMessage : (NSString *)message
156
157
dismissButtonTitle : (NSString *)dismissButtonTitle
157
158
openSettingsButtonTitle : (NSString *)openSettingsButtonTitle
158
- completion : (FLAAuthCompletion )completion {
159
+ completion : (FLADAuthCompletion )completion {
159
160
UIAlertController *alert =
160
161
[UIAlertController alertControllerWithTitle: @" "
161
162
message: message
@@ -189,9 +190,9 @@ - (void)showAlertWithMessage:(NSString *)message
189
190
190
191
- (void )handleAuthReplyWithSuccess : (BOOL )success
191
192
error : (NSError *)error
192
- options : (FLAAuthOptions *)options
193
- strings : (FLAAuthStrings *)strings
194
- completion : (nonnull FLAAuthCompletion )completion {
193
+ options : (FLADAuthOptions *)options
194
+ strings : (FLADAuthStrings *)strings
195
+ completion : (nonnull FLADAuthCompletion )completion {
195
196
NSAssert ([NSThread isMainThread ], @" Response handling must be done on the main thread." );
196
197
if (success) {
197
198
[self handleSucceeded: YES withCompletion: completion];
@@ -219,19 +220,19 @@ - (void)handleAuthReplyWithSuccess:(BOOL)success
219
220
}
220
221
}
221
222
222
- - (void )handleSucceeded : (BOOL )succeeded withCompletion : (nonnull FLAAuthCompletion )completion {
223
- completion (
224
- [FLAAuthResultDetails makeWithResult: (succeeded ? FLAAuthResultSuccess : FLAAuthResultFailure )
225
- errorMessage: nil
226
- errorDetails: nil ],
227
- nil );
223
+ - (void )handleSucceeded : (BOOL )succeeded withCompletion : (nonnull FLADAuthCompletion )completion {
224
+ completion ([FLADAuthResultDetails
225
+ makeWithResult: (succeeded ? FLADAuthResultSuccess : FLADAuthResultFailure )
226
+ errorMessage: nil
227
+ errorDetails: nil ],
228
+ nil );
228
229
}
229
230
230
231
- (void )handleError : (NSError *)authError
231
- withOptions : (FLAAuthOptions *)options
232
- strings : (FLAAuthStrings *)strings
233
- completion : (nonnull FLAAuthCompletion )completion {
234
- FLAAuthResult result = FLAAuthResultErrorNotAvailable ;
232
+ withOptions : (FLADAuthOptions *)options
233
+ strings : (FLADAuthStrings *)strings
234
+ completion : (nonnull FLADAuthCompletion )completion {
235
+ FLADAuthResult result = FLADAuthResultErrorNotAvailable ;
235
236
switch (authError.code ) {
236
237
case LAErrorPasscodeNotSet:
237
238
case LAErrorBiometryNotEnrolled:
@@ -242,8 +243,8 @@ - (void)handleError:(NSError *)authError
242
243
completion: completion];
243
244
return ;
244
245
}
245
- result = authError.code == LAErrorPasscodeNotSet ? FLAAuthResultErrorPasscodeNotSet
246
- : FLAAuthResultErrorNotEnrolled ;
246
+ result = authError.code == LAErrorPasscodeNotSet ? FLADAuthResultErrorPasscodeNotSet
247
+ : FLADAuthResultErrorNotEnrolled ;
247
248
break ;
248
249
case LAErrorBiometryLockout:
249
250
[self showAlertWithMessage: strings.lockOut
@@ -252,9 +253,9 @@ - (void)handleError:(NSError *)authError
252
253
completion: completion];
253
254
return ;
254
255
}
255
- completion ([FLAAuthResultDetails makeWithResult: result
256
- errorMessage: authError.localizedDescription
257
- errorDetails: authError.domain],
256
+ completion ([FLADAuthResultDetails makeWithResult: result
257
+ errorMessage: authError.localizedDescription
258
+ errorDetails: authError.domain],
258
259
nil );
259
260
}
260
261
0 commit comments