Skip to content

Commit

Permalink
[local_auth] Update iOS to Pigeon 13 (#5269)
Browse files Browse the repository at this point in the history
Picks up several breaking changes, including the switch to unwrapped BOOL properties.
  • Loading branch information
stuartmorgan authored Nov 1, 2023
1 parent 6ad40b9 commit e780cb8
Show file tree
Hide file tree
Showing 7 changed files with 124 additions and 76 deletions.
4 changes: 4 additions & 0 deletions packages/local_auth/local_auth_ios/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
## 1.1.5

* Updates to Pigeon 13.

## 1.1.4

* Adds pub topics to package metadata.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,9 +73,9 @@ - (void)testSuccessfullAuthWithBiometrics {
.andDo(backgroundThreadReplyCaller);

XCTestExpectation *expectation = [self expectationWithDescription:@"Result is called"];
[plugin authenticateWithOptions:[FLAAuthOptions makeWithBiometricOnly:@YES
sticky:@NO
useErrorDialogs:@NO]
[plugin authenticateWithOptions:[FLAAuthOptions makeWithBiometricOnly:YES
sticky:NO
useErrorDialogs:NO]
strings:strings
completion:^(FLAAuthResultDetails *_Nullable resultDetails,
FlutterError *_Nullable error) {
Expand Down Expand Up @@ -111,9 +111,9 @@ - (void)testSuccessfullAuthWithoutBiometrics {
.andDo(backgroundThreadReplyCaller);

XCTestExpectation *expectation = [self expectationWithDescription:@"Result is called"];
[plugin authenticateWithOptions:[FLAAuthOptions makeWithBiometricOnly:@NO
sticky:@NO
useErrorDialogs:@NO]
[plugin authenticateWithOptions:[FLAAuthOptions makeWithBiometricOnly:NO
sticky:NO
useErrorDialogs:NO]
strings:strings
completion:^(FLAAuthResultDetails *_Nullable resultDetails,
FlutterError *_Nullable error) {
Expand Down Expand Up @@ -149,9 +149,9 @@ - (void)testFailedAuthWithBiometrics {
.andDo(backgroundThreadReplyCaller);

XCTestExpectation *expectation = [self expectationWithDescription:@"Result is called"];
[plugin authenticateWithOptions:[FLAAuthOptions makeWithBiometricOnly:@YES
sticky:@NO
useErrorDialogs:@NO]
[plugin authenticateWithOptions:[FLAAuthOptions makeWithBiometricOnly:YES
sticky:NO
useErrorDialogs:NO]
strings:strings
completion:^(FLAAuthResultDetails *_Nullable resultDetails,
FlutterError *_Nullable error) {
Expand Down Expand Up @@ -191,9 +191,9 @@ - (void)testFailedWithUnknownErrorCode {
.andDo(backgroundThreadReplyCaller);

XCTestExpectation *expectation = [self expectationWithDescription:@"Result is called"];
[plugin authenticateWithOptions:[FLAAuthOptions makeWithBiometricOnly:@NO
sticky:@NO
useErrorDialogs:@NO]
[plugin authenticateWithOptions:[FLAAuthOptions makeWithBiometricOnly:NO
sticky:NO
useErrorDialogs:NO]
strings:strings
completion:^(FLAAuthResultDetails *_Nullable resultDetails,
FlutterError *_Nullable error) {
Expand Down Expand Up @@ -229,9 +229,9 @@ - (void)testSystemCancelledWithoutStickyAuth {
.andDo(backgroundThreadReplyCaller);

XCTestExpectation *expectation = [self expectationWithDescription:@"Result is called"];
[plugin authenticateWithOptions:[FLAAuthOptions makeWithBiometricOnly:@NO
sticky:@NO
useErrorDialogs:@NO]
[plugin authenticateWithOptions:[FLAAuthOptions makeWithBiometricOnly:NO
sticky:NO
useErrorDialogs:NO]
strings:strings
completion:^(FLAAuthResultDetails *_Nullable resultDetails,
FlutterError *_Nullable error) {
Expand Down Expand Up @@ -267,9 +267,9 @@ - (void)testFailedAuthWithoutBiometrics {
.andDo(backgroundThreadReplyCaller);

XCTestExpectation *expectation = [self expectationWithDescription:@"Result is called"];
[plugin authenticateWithOptions:[FLAAuthOptions makeWithBiometricOnly:@NO
sticky:@NO
useErrorDialogs:@NO]
[plugin authenticateWithOptions:[FLAAuthOptions makeWithBiometricOnly:NO
sticky:NO
useErrorDialogs:NO]
strings:strings
completion:^(FLAAuthResultDetails *_Nullable resultDetails,
FlutterError *_Nullable error) {
Expand Down Expand Up @@ -310,9 +310,9 @@ - (void)testLocalizedFallbackTitle {
.andDo(backgroundThreadReplyCaller);

XCTestExpectation *expectation = [self expectationWithDescription:@"Result is called"];
[plugin authenticateWithOptions:[FLAAuthOptions makeWithBiometricOnly:@NO
sticky:@NO
useErrorDialogs:@NO]
[plugin authenticateWithOptions:[FLAAuthOptions makeWithBiometricOnly:NO
sticky:NO
useErrorDialogs:NO]
strings:strings
completion:^(FLAAuthResultDetails *_Nullable resultDetails,
FlutterError *_Nullable error) {
Expand Down Expand Up @@ -348,9 +348,9 @@ - (void)testSkippedLocalizedFallbackTitle {
.andDo(backgroundThreadReplyCaller);

XCTestExpectation *expectation = [self expectationWithDescription:@"Result is called"];
[plugin authenticateWithOptions:[FLAAuthOptions makeWithBiometricOnly:@NO
sticky:@NO
useErrorDialogs:@NO]
[plugin authenticateWithOptions:[FLAAuthOptions makeWithBiometricOnly:NO
sticky:NO
useErrorDialogs:NO]
strings:strings
completion:^(FLAAuthResultDetails *_Nullable resultDetails,
FlutterError *_Nullable error) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ @implementation FLTLocalAuthPlugin
+ (void)registerWithRegistrar:(NSObject<FlutterPluginRegistrar> *)registrar {
FLTLocalAuthPlugin *instance = [[FLTLocalAuthPlugin alloc] init];
[registrar addApplicationDelegate:instance];
FLALocalAuthApiSetup([registrar messenger], instance);
SetUpFLALocalAuthApi([registrar messenger], instance);
}

- (instancetype)init {
Expand All @@ -86,9 +86,8 @@ - (void)authenticateWithOptions:(nonnull FLAAuthOptions *)options
self.lastCallState = nil;
context.localizedFallbackTitle = strings.localizedFallbackTitle;

LAPolicy policy = options.biometricOnly.boolValue
? LAPolicyDeviceOwnerAuthenticationWithBiometrics
: LAPolicyDeviceOwnerAuthentication;
LAPolicy policy = options.biometricOnly ? LAPolicyDeviceOwnerAuthenticationWithBiometrics
: LAPolicyDeviceOwnerAuthentication;
if ([context canEvaluatePolicy:policy error:&authError]) {
[context evaluatePolicy:policy
localizedReason:strings.reason
Expand Down Expand Up @@ -208,7 +207,7 @@ - (void)handleAuthReplyWithSuccess:(BOOL)success
[self handleError:error withOptions:options strings:strings completion:completion];
return;
case LAErrorSystemCancel:
if ([options.sticky boolValue]) {
if (options.sticky) {
_lastCallState = [[FLAStickyAuthState alloc] initWithOptions:options
strings:strings
resultHandler:completion];
Expand Down Expand Up @@ -237,7 +236,7 @@ - (void)handleError:(NSError *)authError
switch (authError.code) {
case LAErrorPasscodeNotSet:
case LAErrorBiometryNotEnrolled:
if (options.useErrorDialogs.boolValue) {
if (options.useErrorDialogs) {
[self showAlertWithMessage:strings.goToSettingsDescription
dismissButtonTitle:strings.cancelButton
openSettingsButtonTitle:strings.goToSettingsButton
Expand Down
28 changes: 20 additions & 8 deletions packages/local_auth/local_auth_ios/ios/Classes/messages.g.h
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// Copyright 2013 The Flutter Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
// Autogenerated from Pigeon (v9.2.5), do not edit directly.
// Autogenerated from Pigeon (v13.0.0), do not edit directly.
// See also: https://pub.dev/packages/pigeon

#import <Foundation/Foundation.h>
Expand All @@ -27,12 +27,24 @@ typedef NS_ENUM(NSUInteger, FLAAuthResult) {
FLAAuthResultErrorPasscodeNotSet = 4,
};

/// Wrapper for FLAAuthResult to allow for nullability.
@interface FLAAuthResultBox : NSObject
@property(nonatomic, assign) FLAAuthResult value;
- (instancetype)initWithValue:(FLAAuthResult)value;
@end

/// Pigeon equivalent of the subset of BiometricType used by iOS.
typedef NS_ENUM(NSUInteger, FLAAuthBiometric) {
FLAAuthBiometricFace = 0,
FLAAuthBiometricFingerprint = 1,
};

/// Wrapper for FLAAuthBiometric to allow for nullability.
@interface FLAAuthBiometricBox : NSObject
@property(nonatomic, assign) FLAAuthBiometric value;
- (instancetype)initWithValue:(FLAAuthBiometric)value;
@end

@class FLAAuthStrings;
@class FLAAuthOptions;
@class FLAAuthResultDetails;
Expand Down Expand Up @@ -61,12 +73,12 @@ typedef NS_ENUM(NSUInteger, FLAAuthBiometric) {
@interface FLAAuthOptions : NSObject
/// `init` unavailable to enforce nonnull fields, see the `make` class method.
- (instancetype)init NS_UNAVAILABLE;
+ (instancetype)makeWithBiometricOnly:(NSNumber *)biometricOnly
sticky:(NSNumber *)sticky
useErrorDialogs:(NSNumber *)useErrorDialogs;
@property(nonatomic, strong) NSNumber *biometricOnly;
@property(nonatomic, strong) NSNumber *sticky;
@property(nonatomic, strong) NSNumber *useErrorDialogs;
+ (instancetype)makeWithBiometricOnly:(BOOL)biometricOnly
sticky:(BOOL)sticky
useErrorDialogs:(BOOL)useErrorDialogs;
@property(nonatomic, assign) BOOL biometricOnly;
@property(nonatomic, assign) BOOL sticky;
@property(nonatomic, assign) BOOL useErrorDialogs;
@end

@interface FLAAuthResultDetails : NSObject
Expand Down Expand Up @@ -117,7 +129,7 @@ NSObject<FlutterMessageCodec> *FLALocalAuthApiGetCodec(void);
FlutterError *_Nullable))completion;
@end

extern void FLALocalAuthApiSetup(id<FlutterBinaryMessenger> binaryMessenger,
extern void SetUpFLALocalAuthApi(id<FlutterBinaryMessenger> binaryMessenger,
NSObject<FLALocalAuthApi> *_Nullable api);

NS_ASSUME_NONNULL_END
81 changes: 50 additions & 31 deletions packages/local_auth/local_auth_ios/ios/Classes/messages.g.m
Original file line number Diff line number Diff line change
@@ -1,16 +1,43 @@
// Copyright 2013 The Flutter Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
// Autogenerated from Pigeon (v9.2.5), do not edit directly.
// Autogenerated from Pigeon (v13.0.0), do not edit directly.
// See also: https://pub.dev/packages/pigeon

#import "messages.g.h"

#if TARGET_OS_OSX
#import <FlutterMacOS/FlutterMacOS.h>
#else
#import <Flutter/Flutter.h>
#endif

#if !__has_feature(objc_arc)
#error File requires ARC to be enabled.
#endif

/// Possible outcomes of an authentication attempt.
@implementation FLAAuthResultBox
- (instancetype)initWithValue:(FLAAuthResult)value {
self = [super init];
if (self) {
_value = value;
}
return self;
}
@end

/// Pigeon equivalent of the subset of BiometricType used by iOS.
@implementation FLAAuthBiometricBox
- (instancetype)initWithValue:(FLAAuthBiometric)value {
self = [super init];
if (self) {
_value = value;
}
return self;
}
@end

static NSArray *wrapResult(id result, FlutterError *error) {
if (error) {
return @[
Expand Down Expand Up @@ -67,15 +94,10 @@ + (instancetype)makeWithReason:(NSString *)reason
+ (FLAAuthStrings *)fromList:(NSArray *)list {
FLAAuthStrings *pigeonResult = [[FLAAuthStrings alloc] init];
pigeonResult.reason = GetNullableObjectAtIndex(list, 0);
NSAssert(pigeonResult.reason != nil, @"");
pigeonResult.lockOut = GetNullableObjectAtIndex(list, 1);
NSAssert(pigeonResult.lockOut != nil, @"");
pigeonResult.goToSettingsButton = GetNullableObjectAtIndex(list, 2);
NSAssert(pigeonResult.goToSettingsButton != nil, @"");
pigeonResult.goToSettingsDescription = GetNullableObjectAtIndex(list, 3);
NSAssert(pigeonResult.goToSettingsDescription != nil, @"");
pigeonResult.cancelButton = GetNullableObjectAtIndex(list, 4);
NSAssert(pigeonResult.cancelButton != nil, @"");
pigeonResult.localizedFallbackTitle = GetNullableObjectAtIndex(list, 5);
return pigeonResult;
}
Expand All @@ -84,20 +106,20 @@ + (nullable FLAAuthStrings *)nullableFromList:(NSArray *)list {
}
- (NSArray *)toList {
return @[
(self.reason ?: [NSNull null]),
(self.lockOut ?: [NSNull null]),
(self.goToSettingsButton ?: [NSNull null]),
(self.goToSettingsDescription ?: [NSNull null]),
(self.cancelButton ?: [NSNull null]),
(self.localizedFallbackTitle ?: [NSNull null]),
self.reason ?: [NSNull null],
self.lockOut ?: [NSNull null],
self.goToSettingsButton ?: [NSNull null],
self.goToSettingsDescription ?: [NSNull null],
self.cancelButton ?: [NSNull null],
self.localizedFallbackTitle ?: [NSNull null],
];
}
@end

@implementation FLAAuthOptions
+ (instancetype)makeWithBiometricOnly:(NSNumber *)biometricOnly
sticky:(NSNumber *)sticky
useErrorDialogs:(NSNumber *)useErrorDialogs {
+ (instancetype)makeWithBiometricOnly:(BOOL)biometricOnly
sticky:(BOOL)sticky
useErrorDialogs:(BOOL)useErrorDialogs {
FLAAuthOptions *pigeonResult = [[FLAAuthOptions alloc] init];
pigeonResult.biometricOnly = biometricOnly;
pigeonResult.sticky = sticky;
Expand All @@ -106,22 +128,19 @@ + (instancetype)makeWithBiometricOnly:(NSNumber *)biometricOnly
}
+ (FLAAuthOptions *)fromList:(NSArray *)list {
FLAAuthOptions *pigeonResult = [[FLAAuthOptions alloc] init];
pigeonResult.biometricOnly = GetNullableObjectAtIndex(list, 0);
NSAssert(pigeonResult.biometricOnly != nil, @"");
pigeonResult.sticky = GetNullableObjectAtIndex(list, 1);
NSAssert(pigeonResult.sticky != nil, @"");
pigeonResult.useErrorDialogs = GetNullableObjectAtIndex(list, 2);
NSAssert(pigeonResult.useErrorDialogs != nil, @"");
pigeonResult.biometricOnly = [GetNullableObjectAtIndex(list, 0) boolValue];
pigeonResult.sticky = [GetNullableObjectAtIndex(list, 1) boolValue];
pigeonResult.useErrorDialogs = [GetNullableObjectAtIndex(list, 2) boolValue];
return pigeonResult;
}
+ (nullable FLAAuthOptions *)nullableFromList:(NSArray *)list {
return (list) ? [FLAAuthOptions fromList:list] : nil;
}
- (NSArray *)toList {
return @[
(self.biometricOnly ?: [NSNull null]),
(self.sticky ?: [NSNull null]),
(self.useErrorDialogs ?: [NSNull null]),
@(self.biometricOnly),
@(self.sticky),
@(self.useErrorDialogs),
];
}
@end
Expand Down Expand Up @@ -149,8 +168,8 @@ + (nullable FLAAuthResultDetails *)nullableFromList:(NSArray *)list {
- (NSArray *)toList {
return @[
@(self.result),
(self.errorMessage ?: [NSNull null]),
(self.errorDetails ?: [NSNull null]),
self.errorMessage ?: [NSNull null],
self.errorDetails ?: [NSNull null],
];
}
@end
Expand Down Expand Up @@ -239,12 +258,12 @@ - (FlutterStandardReader *)readerWithData:(NSData *)data {
return sSharedObject;
}

void FLALocalAuthApiSetup(id<FlutterBinaryMessenger> binaryMessenger,
void SetUpFLALocalAuthApi(id<FlutterBinaryMessenger> binaryMessenger,
NSObject<FLALocalAuthApi> *api) {
/// Returns true if this device supports authentication.
{
FlutterBasicMessageChannel *channel = [[FlutterBasicMessageChannel alloc]
initWithName:@"dev.flutter.pigeon.LocalAuthApi.isDeviceSupported"
initWithName:@"dev.flutter.pigeon.local_auth_ios.LocalAuthApi.isDeviceSupported"
binaryMessenger:binaryMessenger
codec:FLALocalAuthApiGetCodec()];
if (api) {
Expand All @@ -265,7 +284,7 @@ void FLALocalAuthApiSetup(id<FlutterBinaryMessenger> binaryMessenger,
/// any biometrics are enrolled or not.
{
FlutterBasicMessageChannel *channel = [[FlutterBasicMessageChannel alloc]
initWithName:@"dev.flutter.pigeon.LocalAuthApi.deviceCanSupportBiometrics"
initWithName:@"dev.flutter.pigeon.local_auth_ios.LocalAuthApi.deviceCanSupportBiometrics"
binaryMessenger:binaryMessenger
codec:FLALocalAuthApiGetCodec()];
if (api) {
Expand All @@ -286,7 +305,7 @@ void FLALocalAuthApiSetup(id<FlutterBinaryMessenger> binaryMessenger,
/// without additional setup.
{
FlutterBasicMessageChannel *channel = [[FlutterBasicMessageChannel alloc]
initWithName:@"dev.flutter.pigeon.LocalAuthApi.getEnrolledBiometrics"
initWithName:@"dev.flutter.pigeon.local_auth_ios.LocalAuthApi.getEnrolledBiometrics"
binaryMessenger:binaryMessenger
codec:FLALocalAuthApiGetCodec()];
if (api) {
Expand All @@ -307,7 +326,7 @@ void FLALocalAuthApiSetup(id<FlutterBinaryMessenger> binaryMessenger,
/// [strings] for any UI.
{
FlutterBasicMessageChannel *channel = [[FlutterBasicMessageChannel alloc]
initWithName:@"dev.flutter.pigeon.LocalAuthApi.authenticate"
initWithName:@"dev.flutter.pigeon.local_auth_ios.LocalAuthApi.authenticate"
binaryMessenger:binaryMessenger
codec:FLALocalAuthApiGetCodec()];
if (api) {
Expand Down
Loading

0 comments on commit e780cb8

Please sign in to comment.