From be43856ab744f9a824d220d2bdeab63f1b078be0 Mon Sep 17 00:00:00 2001 From: Huan Lin Date: Wed, 10 Jul 2024 22:44:38 -0700 Subject: [PATCH 1/2] [ios]use DefaultLauncher to fix compile error when conforming UIApplication to Launcher due to main actor annotation bump version --- .../url_launcher_ios/CHANGELOG.md | 4 ++++ .../Sources/url_launcher_ios/Launcher.swift | 20 +++++++++++++++++-- .../url_launcher_ios/URLLauncherPlugin.swift | 2 +- .../url_launcher_ios/pubspec.yaml | 2 +- 4 files changed, 24 insertions(+), 4 deletions(-) diff --git a/packages/url_launcher/url_launcher_ios/CHANGELOG.md b/packages/url_launcher/url_launcher_ios/CHANGELOG.md index 0c6d13e0941e..63dbcaa6a48d 100644 --- a/packages/url_launcher/url_launcher_ios/CHANGELOG.md +++ b/packages/url_launcher/url_launcher_ios/CHANGELOG.md @@ -1,3 +1,7 @@ +## 6.3.1 + +* Fixes a compile error when comforming UIApplication to Launcher in iOS 18 Beta 3. + ## 6.3.0 * Adds Swift Package Manager compatibility. diff --git a/packages/url_launcher/url_launcher_ios/ios/url_launcher_ios/Sources/url_launcher_ios/Launcher.swift b/packages/url_launcher/url_launcher_ios/ios/url_launcher_ios/Sources/url_launcher_ios/Launcher.swift index 454dd53fbb9c..26bf2b199ef7 100644 --- a/packages/url_launcher/url_launcher_ios/ios/url_launcher_ios/Sources/url_launcher_ios/Launcher.swift +++ b/packages/url_launcher/url_launcher_ios/ios/url_launcher_ios/Sources/url_launcher_ios/Launcher.swift @@ -18,5 +18,21 @@ protocol Launcher { completionHandler completion: ((Bool) -> Void)?) } -/// Launcher is intentionally a direct passthroguh to UIApplication. -extension UIApplication: Launcher {} +// TODO(hellohuanlin): This wrapper is a workaround for iOS 18 Beta 3 where completionHandler is annotated with @MainActor @Sendable, resulting in compile error when conforming UIApplication to Launcher. We should try again in newer betas. +/// A default URL launcher. +final class DefaultLauncher: Launcher { + func canOpenURL(_ url: URL) -> Bool { + return UIApplication.shared.canOpenURL(url) + } + + func open( + _ url: URL, + options: [UIApplication.OpenExternalURLOptionsKey: Any], + completionHandler completion: ((Bool) -> Void)?) + { + UIApplication.shared.open( + url, + options: options, + completionHandler: completion) + } +} diff --git a/packages/url_launcher/url_launcher_ios/ios/url_launcher_ios/Sources/url_launcher_ios/URLLauncherPlugin.swift b/packages/url_launcher/url_launcher_ios/ios/url_launcher_ios/Sources/url_launcher_ios/URLLauncherPlugin.swift index 44718dee7323..9fdec7ee5ae3 100644 --- a/packages/url_launcher/url_launcher_ios/ios/url_launcher_ios/Sources/url_launcher_ios/URLLauncherPlugin.swift +++ b/packages/url_launcher/url_launcher_ios/ios/url_launcher_ios/Sources/url_launcher_ios/URLLauncherPlugin.swift @@ -22,7 +22,7 @@ public final class URLLauncherPlugin: NSObject, FlutterPlugin, UrlLauncherApi { UIApplication.shared.keyWindow?.rootViewController?.topViewController } - init(launcher: Launcher = UIApplication.shared) { + init(launcher: Launcher = DefaultLauncher()) { self.launcher = launcher } diff --git a/packages/url_launcher/url_launcher_ios/pubspec.yaml b/packages/url_launcher/url_launcher_ios/pubspec.yaml index 65e9c2048351..25a227503f0e 100644 --- a/packages/url_launcher/url_launcher_ios/pubspec.yaml +++ b/packages/url_launcher/url_launcher_ios/pubspec.yaml @@ -2,7 +2,7 @@ name: url_launcher_ios description: iOS implementation of the url_launcher plugin. repository: https://github.com/flutter/packages/tree/main/packages/url_launcher/url_launcher_ios issue_tracker: https://github.com/flutter/flutter/issues?q=is%3Aissue+is%3Aopen+label%3A%22p%3A+url_launcher%22 -version: 6.3.0 +version: 6.3.1 environment: sdk: ^3.2.3 From ce455e87a4db3642fe2d9d36c8da1ee72d7cffea Mon Sep 17 00:00:00 2001 From: Huan Lin Date: Thu, 11 Jul 2024 17:04:35 -0700 Subject: [PATCH 2/2] format --- .../Sources/url_launcher_ios/Launcher.swift | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/packages/url_launcher/url_launcher_ios/ios/url_launcher_ios/Sources/url_launcher_ios/Launcher.swift b/packages/url_launcher/url_launcher_ios/ios/url_launcher_ios/Sources/url_launcher_ios/Launcher.swift index 26bf2b199ef7..1f64b95c642d 100644 --- a/packages/url_launcher/url_launcher_ios/ios/url_launcher_ios/Sources/url_launcher_ios/Launcher.swift +++ b/packages/url_launcher/url_launcher_ios/ios/url_launcher_ios/Sources/url_launcher_ios/Launcher.swift @@ -24,12 +24,12 @@ final class DefaultLauncher: Launcher { func canOpenURL(_ url: URL) -> Bool { return UIApplication.shared.canOpenURL(url) } - + func open( _ url: URL, options: [UIApplication.OpenExternalURLOptionsKey: Any], - completionHandler completion: ((Bool) -> Void)?) - { + completionHandler completion: ((Bool) -> Void)? + ) { UIApplication.shared.open( url, options: options,