diff --git a/packages/local_auth/local_auth_darwin/CHANGELOG.md b/packages/local_auth/local_auth_darwin/CHANGELOG.md index 082a2438c3f9..d4b296d3ceef 100644 --- a/packages/local_auth/local_auth_darwin/CHANGELOG.md +++ b/packages/local_auth/local_auth_darwin/CHANGELOG.md @@ -1,3 +1,8 @@ +## 2.0.2 + +* Improves compatibility with UIScene. +* Updates minimum supported SDK version to Flutter 3.38/Dart 3.10. + ## 2.0.1 * Updates to Pigeon 26. diff --git a/packages/local_auth/local_auth_darwin/darwin/local_auth_darwin/Sources/local_auth_darwin/LocalAuthPlugin.swift b/packages/local_auth/local_auth_darwin/darwin/local_auth_darwin/Sources/local_auth_darwin/LocalAuthPlugin.swift index 3222b795eb5d..e93b1977f3c5 100644 --- a/packages/local_auth/local_auth_darwin/darwin/local_auth_darwin/Sources/local_auth_darwin/LocalAuthPlugin.swift +++ b/packages/local_auth/local_auth_darwin/darwin/local_auth_darwin/Sources/local_auth_darwin/LocalAuthPlugin.swift @@ -43,7 +43,13 @@ public final class LocalAuthPlugin: NSObject, FlutterPlugin, LocalAuthApi, @unch public static func register(with registrar: FlutterPluginRegistrar) { let instance = LocalAuthPlugin( contextFactory: DefaultAuthContextFactory()) + // Register for both application and scene delegates for backward compatibility. + // Apps using UIScene lifecycle will receive sceneDidBecomeActive, + // while apps not yet migrated will receive applicationDidBecomeActive. registrar.addApplicationDelegate(instance) + #if os(iOS) + registrar.addSceneDelegate(instance) + #endif // Workaround for https://github.com/flutter/flutter/issues/118103. #if os(iOS) let messenger = registrar.messenger() @@ -249,18 +255,36 @@ public final class LocalAuthPlugin: NSObject, FlutterPlugin, LocalAuthApi, @unch )) } + private func retryStickyAuth() { + if let lastCallState = self.lastCallState { + authenticate( + options: lastCallState.options, + strings: lastCallState.strings, + completion: lastCallState.resultHandler) + } + } + // MARK: App delegate - // This method is called when the app is resumed from the background only on iOS + // These methods are called when the app is resumed from the background only on iOS. + // Both are kept for backward compatibility: sceneDidBecomeActive for apps using UIScene lifecycle, + // and applicationDidBecomeActive for apps that haven't migrated yet. #if os(iOS) + @MainActor + public func sceneDidBecomeActive(_ scene: UIScene) { + retryStickyAuth() + } + + @MainActor public func applicationDidBecomeActive(_ application: UIApplication) { - if let lastCallState = self.lastCallState { - authenticate( - options: lastCallState.options, - strings: lastCallState.strings, - completion: lastCallState.resultHandler) - } + retryStickyAuth() } #endif // os(iOS) } + +// MARK: - FlutterSceneLifeCycleDelegate + +#if os(iOS) + extension LocalAuthPlugin: FlutterSceneLifeCycleDelegate {} +#endif diff --git a/packages/local_auth/local_auth_darwin/example/ios/Runner/AppDelegate.h b/packages/local_auth/local_auth_darwin/example/ios/Runner/AppDelegate.h index 721cca1e11bb..c9212a60cb5d 100644 --- a/packages/local_auth/local_auth_darwin/example/ios/Runner/AppDelegate.h +++ b/packages/local_auth/local_auth_darwin/example/ios/Runner/AppDelegate.h @@ -5,6 +5,9 @@ #import #import -@interface AppDelegate : FlutterAppDelegate +// FlutterImplicitEngineDelegate is required for UIScene lifecycle. +// It provides a callback (didInitializeImplicitFlutterEngine:) that fires +// after the Flutter engine is ready, which is when plugins should be registered. +@interface AppDelegate : FlutterAppDelegate @end diff --git a/packages/local_auth/local_auth_darwin/example/ios/Runner/AppDelegate.m b/packages/local_auth/local_auth_darwin/example/ios/Runner/AppDelegate.m index fff9545d5055..27b4d252c26f 100644 --- a/packages/local_auth/local_auth_darwin/example/ios/Runner/AppDelegate.m +++ b/packages/local_auth/local_auth_darwin/example/ios/Runner/AppDelegate.m @@ -9,9 +9,12 @@ @implementation AppDelegate - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions { - [GeneratedPluginRegistrant registerWithRegistry:self]; // Override point for customization after application launch. return [super application:application didFinishLaunchingWithOptions:launchOptions]; } +- (void)didInitializeImplicitFlutterEngine:(NSObject *)engineBridge { + [GeneratedPluginRegistrant registerWithRegistry:engineBridge.pluginRegistry]; +} + @end diff --git a/packages/local_auth/local_auth_darwin/example/ios/Runner/Info.plist b/packages/local_auth/local_auth_darwin/example/ios/Runner/Info.plist index 2dc92f5dff1c..08be6c437334 100644 --- a/packages/local_auth/local_auth_darwin/example/ios/Runner/Info.plist +++ b/packages/local_auth/local_auth_darwin/example/ios/Runner/Info.plist @@ -49,5 +49,26 @@ UIApplicationSupportsIndirectInputEvents + UIApplicationSceneManifest + + UIApplicationSupportsMultipleScenes + + UISceneConfigurations + + UIWindowSceneSessionRoleApplication + + + UISceneClassName + UIWindowScene + UISceneDelegateClassName + FlutterSceneDelegate + UISceneConfigurationName + flutter + UISceneStoryboardFile + Main + + + + diff --git a/packages/local_auth/local_auth_darwin/pubspec.yaml b/packages/local_auth/local_auth_darwin/pubspec.yaml index 6ececfdadbfd..a2ceb77e104d 100644 --- a/packages/local_auth/local_auth_darwin/pubspec.yaml +++ b/packages/local_auth/local_auth_darwin/pubspec.yaml @@ -2,11 +2,11 @@ name: local_auth_darwin description: iOS implementation of the local_auth plugin. repository: https://github.com/flutter/packages/tree/main/packages/local_auth/local_auth_darwin issue_tracker: https://github.com/flutter/flutter/issues?q=is%3Aissue+is%3Aopen+label%3A%22p%3A+local_auth%22 -version: 2.0.1 +version: 2.0.2 environment: - sdk: ^3.9.0 - flutter: ">=3.35.0" + sdk: ^3.10.0 + flutter: ">=3.38.0" flutter: plugin: