Skip to content

Commit be43856

Browse files
committed
[ios]use DefaultLauncher to fix compile error when conforming UIApplication to Launcher due to main actor annotation
bump version
1 parent ea35fc6 commit be43856

File tree

4 files changed

+24
-4
lines changed

4 files changed

+24
-4
lines changed

packages/url_launcher/url_launcher_ios/CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
## 6.3.1
2+
3+
* Fixes a compile error when comforming UIApplication to Launcher in iOS 18 Beta 3.
4+
15
## 6.3.0
26

37
* Adds Swift Package Manager compatibility.

packages/url_launcher/url_launcher_ios/ios/url_launcher_ios/Sources/url_launcher_ios/Launcher.swift

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,5 +18,21 @@ protocol Launcher {
1818
completionHandler completion: ((Bool) -> Void)?)
1919
}
2020

21-
/// Launcher is intentionally a direct passthroguh to UIApplication.
22-
extension UIApplication: Launcher {}
21+
// 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.
22+
/// A default URL launcher.
23+
final class DefaultLauncher: Launcher {
24+
func canOpenURL(_ url: URL) -> Bool {
25+
return UIApplication.shared.canOpenURL(url)
26+
}
27+
28+
func open(
29+
_ url: URL,
30+
options: [UIApplication.OpenExternalURLOptionsKey: Any],
31+
completionHandler completion: ((Bool) -> Void)?)
32+
{
33+
UIApplication.shared.open(
34+
url,
35+
options: options,
36+
completionHandler: completion)
37+
}
38+
}

packages/url_launcher/url_launcher_ios/ios/url_launcher_ios/Sources/url_launcher_ios/URLLauncherPlugin.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ public final class URLLauncherPlugin: NSObject, FlutterPlugin, UrlLauncherApi {
2222
UIApplication.shared.keyWindow?.rootViewController?.topViewController
2323
}
2424

25-
init(launcher: Launcher = UIApplication.shared) {
25+
init(launcher: Launcher = DefaultLauncher()) {
2626
self.launcher = launcher
2727
}
2828

packages/url_launcher/url_launcher_ios/pubspec.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ name: url_launcher_ios
22
description: iOS implementation of the url_launcher plugin.
33
repository: https://github.com/flutter/packages/tree/main/packages/url_launcher/url_launcher_ios
44
issue_tracker: https://github.com/flutter/flutter/issues?q=is%3Aissue+is%3Aopen+label%3A%22p%3A+url_launcher%22
5-
version: 6.3.0
5+
version: 6.3.1
66

77
environment:
88
sdk: ^3.2.3

0 commit comments

Comments
 (0)