From 3403990cb3b21df0def69a739e43606f86cadc18 Mon Sep 17 00:00:00 2001 From: StanleyCocos Date: Fri, 7 Feb 2025 14:32:07 +0800 Subject: [PATCH 01/11] fix(url_launcher): When not fully loaded, clicking close causes the callback to not be triggered correctly. --- packages/url_launcher/url_launcher/CHANGELOG.md | 3 ++- .../Sources/url_launcher_ios/URLLaunchSession.swift | 5 +++++ 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/packages/url_launcher/url_launcher/CHANGELOG.md b/packages/url_launcher/url_launcher/CHANGELOG.md index 83f67b28e59..7f02d6e4419 100644 --- a/packages/url_launcher/url_launcher/CHANGELOG.md +++ b/packages/url_launcher/url_launcher/CHANGELOG.md @@ -1,6 +1,7 @@ -## NEXT +## 6.3.2 * Updates minimum supported SDK version to Flutter 3.22/Dart 3.4. +* Fixes When not fully loaded, clicking close causes the callback to not be triggered correctly. ## 6.3.1 diff --git a/packages/url_launcher/url_launcher_ios/ios/url_launcher_ios/Sources/url_launcher_ios/URLLaunchSession.swift b/packages/url_launcher/url_launcher_ios/ios/url_launcher_ios/Sources/url_launcher_ios/URLLaunchSession.swift index b0761e57f08..d7bafbfce48 100644 --- a/packages/url_launcher/url_launcher_ios/ios/url_launcher_ios/Sources/url_launcher_ios/URLLaunchSession.swift +++ b/packages/url_launcher/url_launcher_ios/ios/url_launcher_ios/Sources/url_launcher_ios/URLLaunchSession.swift @@ -12,6 +12,7 @@ final class URLLaunchSession: NSObject, SFSafariViewControllerDelegate { private let completion: OpenInSafariCompletionHandler private let url: URL + private var isLoadCompleted: Bool? /// The Safari view controller used for displaying the URL. let safariViewController: SFSafariViewController @@ -46,12 +47,16 @@ final class URLLaunchSession: NSObject, SFSafariViewControllerDelegate { } else { completion(.success(.failedToLoad)) } + isLoadCompleted = didLoadSuccessfully; } /// Called when the user finishes using the Safari view controller. /// /// - Parameter controller: The Safari view controller. func safariViewControllerDidFinish(_ controller: SFSafariViewController) { + if isLoadCompleted == nil { + completion(.success(.failedToLoad)) + } controller.dismiss(animated: true, completion: nil) didFinish?() } From 6082e8c9b6f1e69f0dbd4cb234fe09dd5b42b9a9 Mon Sep 17 00:00:00 2001 From: StanleyCocos Date: Fri, 7 Feb 2025 14:56:34 +0800 Subject: [PATCH 02/11] fix: change log --- packages/url_launcher/url_launcher/CHANGELOG.md | 3 +-- packages/url_launcher/url_launcher_ios/CHANGELOG.md | 3 ++- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/packages/url_launcher/url_launcher/CHANGELOG.md b/packages/url_launcher/url_launcher/CHANGELOG.md index 7f02d6e4419..83f67b28e59 100644 --- a/packages/url_launcher/url_launcher/CHANGELOG.md +++ b/packages/url_launcher/url_launcher/CHANGELOG.md @@ -1,7 +1,6 @@ -## 6.3.2 +## NEXT * Updates minimum supported SDK version to Flutter 3.22/Dart 3.4. -* Fixes When not fully loaded, clicking close causes the callback to not be triggered correctly. ## 6.3.1 diff --git a/packages/url_launcher/url_launcher_ios/CHANGELOG.md b/packages/url_launcher/url_launcher_ios/CHANGELOG.md index a7a283075d4..e23db04281b 100644 --- a/packages/url_launcher/url_launcher_ios/CHANGELOG.md +++ b/packages/url_launcher/url_launcher_ios/CHANGELOG.md @@ -1,6 +1,7 @@ -## NEXT +## 6.3.3 * Updates minimum supported SDK version to Flutter 3.22/Dart 3.4. +* Fixes When not fully loaded, clicking close causes the callback to not be triggered correctly. ## 6.3.2 From 13e30582fe066fe7adb8d295b23b096078ff66cf Mon Sep 17 00:00:00 2001 From: StanleyCocos Date: Fri, 7 Feb 2025 15:14:50 +0800 Subject: [PATCH 03/11] fix: format --- .../Sources/url_launcher_ios/URLLaunchSession.swift | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/url_launcher/url_launcher_ios/ios/url_launcher_ios/Sources/url_launcher_ios/URLLaunchSession.swift b/packages/url_launcher/url_launcher_ios/ios/url_launcher_ios/Sources/url_launcher_ios/URLLaunchSession.swift index d7bafbfce48..c8f37391eae 100644 --- a/packages/url_launcher/url_launcher_ios/ios/url_launcher_ios/Sources/url_launcher_ios/URLLaunchSession.swift +++ b/packages/url_launcher/url_launcher_ios/ios/url_launcher_ios/Sources/url_launcher_ios/URLLaunchSession.swift @@ -47,7 +47,7 @@ final class URLLaunchSession: NSObject, SFSafariViewControllerDelegate { } else { completion(.success(.failedToLoad)) } - isLoadCompleted = didLoadSuccessfully; + isLoadCompleted = didLoadSuccessfully } /// Called when the user finishes using the Safari view controller. From 87a4a3a5c1029a9266e605e5eee7b8356e60005b Mon Sep 17 00:00:00 2001 From: StanleyCocos Date: Fri, 7 Feb 2025 15:16:44 +0800 Subject: [PATCH 04/11] fix: chenge log --- packages/url_launcher/url_launcher_ios/CHANGELOG.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/url_launcher/url_launcher_ios/CHANGELOG.md b/packages/url_launcher/url_launcher_ios/CHANGELOG.md index e23db04281b..a0bf515e7db 100644 --- a/packages/url_launcher/url_launcher_ios/CHANGELOG.md +++ b/packages/url_launcher/url_launcher_ios/CHANGELOG.md @@ -1,4 +1,4 @@ -## 6.3.3 +## NEXT * Updates minimum supported SDK version to Flutter 3.22/Dart 3.4. * Fixes When not fully loaded, clicking close causes the callback to not be triggered correctly. From 940b3114dcddf409f91f5c97ac1e9f686565c71c Mon Sep 17 00:00:00 2001 From: StanleyCocos Date: Fri, 7 Feb 2025 15:29:38 +0800 Subject: [PATCH 05/11] fix: test --- packages/url_launcher/url_launcher_ios/CHANGELOG.md | 2 +- packages/url_launcher/url_launcher_ios/pubspec.yaml | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/packages/url_launcher/url_launcher_ios/CHANGELOG.md b/packages/url_launcher/url_launcher_ios/CHANGELOG.md index a0bf515e7db..e23db04281b 100644 --- a/packages/url_launcher/url_launcher_ios/CHANGELOG.md +++ b/packages/url_launcher/url_launcher_ios/CHANGELOG.md @@ -1,4 +1,4 @@ -## NEXT +## 6.3.3 * Updates minimum supported SDK version to Flutter 3.22/Dart 3.4. * Fixes When not fully loaded, clicking close causes the callback to not be triggered correctly. diff --git a/packages/url_launcher/url_launcher_ios/pubspec.yaml b/packages/url_launcher/url_launcher_ios/pubspec.yaml index 4d11751a4a9..f6fa82f5dc7 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.2 +version: 6.3.3 environment: sdk: ^3.4.0 From 4f733e59285438507f3f31baeefc19823ecfc0e9 Mon Sep 17 00:00:00 2001 From: StanleyCocos Date: Sat, 8 Feb 2025 10:37:26 +0800 Subject: [PATCH 06/11] fix: type --- .../Sources/url_launcher_ios/URLLaunchSession.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/URLLaunchSession.swift b/packages/url_launcher/url_launcher_ios/ios/url_launcher_ios/Sources/url_launcher_ios/URLLaunchSession.swift index c8f37391eae..9953d2f574f 100644 --- a/packages/url_launcher/url_launcher_ios/ios/url_launcher_ios/Sources/url_launcher_ios/URLLaunchSession.swift +++ b/packages/url_launcher/url_launcher_ios/ios/url_launcher_ios/Sources/url_launcher_ios/URLLaunchSession.swift @@ -12,7 +12,7 @@ final class URLLaunchSession: NSObject, SFSafariViewControllerDelegate { private let completion: OpenInSafariCompletionHandler private let url: URL - private var isLoadCompleted: Bool? + private var isLoadCompleted: Bool = false /// The Safari view controller used for displaying the URL. let safariViewController: SFSafariViewController @@ -47,14 +47,14 @@ final class URLLaunchSession: NSObject, SFSafariViewControllerDelegate { } else { completion(.success(.failedToLoad)) } - isLoadCompleted = didLoadSuccessfully + isLoadCompleted = true } /// Called when the user finishes using the Safari view controller. /// /// - Parameter controller: The Safari view controller. func safariViewControllerDidFinish(_ controller: SFSafariViewController) { - if isLoadCompleted == nil { + if !isLoadCompleted { completion(.success(.failedToLoad)) } controller.dismiss(animated: true, completion: nil) From 2c0d46b17ee71f71dde6be597326f3aad4ce9a8b Mon Sep 17 00:00:00 2001 From: StanleyCocos Date: Mon, 10 Feb 2025 11:02:56 +0800 Subject: [PATCH 07/11] fix: test --- .../ios/RunnerTests/URLLauncherTests.swift | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/packages/url_launcher/url_launcher_ios/example/ios/RunnerTests/URLLauncherTests.swift b/packages/url_launcher/url_launcher_ios/example/ios/RunnerTests/URLLauncherTests.swift index 966a3d63e6d..f0757e77e72 100644 --- a/packages/url_launcher/url_launcher_ios/example/ios/RunnerTests/URLLauncherTests.swift +++ b/packages/url_launcher/url_launcher_ios/example/ios/RunnerTests/URLLauncherTests.swift @@ -131,6 +131,24 @@ final class URLLauncherTests: XCTestCase { XCTAssertEqual(launcher.passedOptions?[.universalLinksOnly] as? Bool, true) } + func testLaunchSafariViewControllerWithClose() { + let launcher = FakeLauncher() + let plugin = createPlugin(launcher: launcher) + + let expectation = XCTestExpectation(description: "completion called") + plugin.openUrlInSafariViewController(url: "https://flutter.dev") { result in + switch result { + case .success(let details): + XCTAssertEqual(details, .failedToLoad) + case .failure(let error): + XCTFail("Unexpected error: \(error)") + } + expectation.fulfill() + } + plugin.closeSafariViewController() + wait(for: [expectation], timeout: 30) + } + } final private class FakeLauncher: NSObject, Launcher { From 2a095f21f2e90cf31ac33d1b23fb0466bd68b689 Mon Sep 17 00:00:00 2001 From: StanleyCocos Date: Thu, 13 Feb 2025 09:41:12 +0800 Subject: [PATCH 08/11] fix: changelog --- packages/url_launcher/url_launcher_ios/CHANGELOG.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/url_launcher/url_launcher_ios/CHANGELOG.md b/packages/url_launcher/url_launcher_ios/CHANGELOG.md index e23db04281b..5103c4e2ec1 100644 --- a/packages/url_launcher/url_launcher_ios/CHANGELOG.md +++ b/packages/url_launcher/url_launcher_ios/CHANGELOG.md @@ -1,7 +1,7 @@ ## 6.3.3 * Updates minimum supported SDK version to Flutter 3.22/Dart 3.4. -* Fixes When not fully loaded, clicking close causes the callback to not be triggered correctly. +* Ensures the completion callback is invoked if the user dismisses the Safari view before the initial URL load completes. ## 6.3.2 From 99359e7363032957f6f37f53ce9d3688b6fa1edc Mon Sep 17 00:00:00 2001 From: StanleyCocos Date: Tue, 18 Feb 2025 09:12:51 +0800 Subject: [PATCH 09/11] fix: comment --- packages/url_launcher/url_launcher_ios/pigeons/messages.dart | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/url_launcher/url_launcher_ios/pigeons/messages.dart b/packages/url_launcher/url_launcher_ios/pigeons/messages.dart index c7097b41a74..aeafa4b69c8 100644 --- a/packages/url_launcher/url_launcher_ios/pigeons/messages.dart +++ b/packages/url_launcher/url_launcher_ios/pigeons/messages.dart @@ -27,7 +27,7 @@ enum InAppLoadResult { /// The URL was successfully loaded. success, - /// The URL did not load successfully. + /// The URL did not load successfully (or close the SFSafariViewController earlier). failedToLoad, /// The URL could not be launched because it is invalid. From a2c8559b95ca78c70bb1ee1e3937271480f7d06e Mon Sep 17 00:00:00 2001 From: StanleyCocos Date: Fri, 21 Feb 2025 21:28:54 +0800 Subject: [PATCH 10/11] fix: comment --- packages/url_launcher/url_launcher_ios/pigeons/messages.dart | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/url_launcher/url_launcher_ios/pigeons/messages.dart b/packages/url_launcher/url_launcher_ios/pigeons/messages.dart index aeafa4b69c8..20ecab2b8a1 100644 --- a/packages/url_launcher/url_launcher_ios/pigeons/messages.dart +++ b/packages/url_launcher/url_launcher_ios/pigeons/messages.dart @@ -27,7 +27,7 @@ enum InAppLoadResult { /// The URL was successfully loaded. success, - /// The URL did not load successfully (or close the SFSafariViewController earlier). + /// The URL did not load successfully (or the user closed the view controller before it loaded). failedToLoad, /// The URL could not be launched because it is invalid. From 5e7b70e006033697d14a8dcc27411b818e712932 Mon Sep 17 00:00:00 2001 From: StanleyCocos Date: Mon, 17 Mar 2025 10:07:16 +0800 Subject: [PATCH 11/11] add dismissed --- .../example/ios/RunnerTests/URLLauncherTests.swift | 2 +- .../Sources/url_launcher_ios/URLLaunchSession.swift | 2 +- .../Sources/url_launcher_ios/messages.g.swift | 2 ++ .../url_launcher/url_launcher_ios/lib/src/messages.g.dart | 3 +++ .../url_launcher/url_launcher_ios/lib/url_launcher_ios.dart | 2 ++ packages/url_launcher/url_launcher_ios/pigeons/messages.dart | 5 ++++- 6 files changed, 13 insertions(+), 3 deletions(-) diff --git a/packages/url_launcher/url_launcher_ios/example/ios/RunnerTests/URLLauncherTests.swift b/packages/url_launcher/url_launcher_ios/example/ios/RunnerTests/URLLauncherTests.swift index f0757e77e72..3b994ad49f6 100644 --- a/packages/url_launcher/url_launcher_ios/example/ios/RunnerTests/URLLauncherTests.swift +++ b/packages/url_launcher/url_launcher_ios/example/ios/RunnerTests/URLLauncherTests.swift @@ -139,7 +139,7 @@ final class URLLauncherTests: XCTestCase { plugin.openUrlInSafariViewController(url: "https://flutter.dev") { result in switch result { case .success(let details): - XCTAssertEqual(details, .failedToLoad) + XCTAssertEqual(details, .dismissed) case .failure(let error): XCTFail("Unexpected error: \(error)") } diff --git a/packages/url_launcher/url_launcher_ios/ios/url_launcher_ios/Sources/url_launcher_ios/URLLaunchSession.swift b/packages/url_launcher/url_launcher_ios/ios/url_launcher_ios/Sources/url_launcher_ios/URLLaunchSession.swift index 9953d2f574f..7457eddf625 100644 --- a/packages/url_launcher/url_launcher_ios/ios/url_launcher_ios/Sources/url_launcher_ios/URLLaunchSession.swift +++ b/packages/url_launcher/url_launcher_ios/ios/url_launcher_ios/Sources/url_launcher_ios/URLLaunchSession.swift @@ -55,7 +55,7 @@ final class URLLaunchSession: NSObject, SFSafariViewControllerDelegate { /// - Parameter controller: The Safari view controller. func safariViewControllerDidFinish(_ controller: SFSafariViewController) { if !isLoadCompleted { - completion(.success(.failedToLoad)) + completion(.success(.dismissed)) } controller.dismiss(animated: true, completion: nil) didFinish?() diff --git a/packages/url_launcher/url_launcher_ios/ios/url_launcher_ios/Sources/url_launcher_ios/messages.g.swift b/packages/url_launcher/url_launcher_ios/ios/url_launcher_ios/Sources/url_launcher_ios/messages.g.swift index 4c9c4693e89..85e1e3944c2 100644 --- a/packages/url_launcher/url_launcher_ios/ios/url_launcher_ios/Sources/url_launcher_ios/messages.g.swift +++ b/packages/url_launcher/url_launcher_ios/ios/url_launcher_ios/Sources/url_launcher_ios/messages.g.swift @@ -85,6 +85,8 @@ enum InAppLoadResult: Int { case failedToLoad = 1 /// The URL could not be launched because it is invalid. case invalidUrl = 2 + /// The controller was closed before loading. + case dismissed = 3 } private class messagesPigeonCodecReader: FlutterStandardReader { diff --git a/packages/url_launcher/url_launcher_ios/lib/src/messages.g.dart b/packages/url_launcher/url_launcher_ios/lib/src/messages.g.dart index b4963035976..8aeea1a66a1 100644 --- a/packages/url_launcher/url_launcher_ios/lib/src/messages.g.dart +++ b/packages/url_launcher/url_launcher_ios/lib/src/messages.g.dart @@ -40,6 +40,9 @@ enum InAppLoadResult { /// The URL could not be launched because it is invalid. invalidUrl, + + /// The controller was closed before loading. + dismissed, } class _PigeonCodec extends StandardMessageCodec { diff --git a/packages/url_launcher/url_launcher_ios/lib/url_launcher_ios.dart b/packages/url_launcher/url_launcher_ios/lib/url_launcher_ios.dart index bb289abc569..27f48681d85 100644 --- a/packages/url_launcher/url_launcher_ios/lib/url_launcher_ios.dart +++ b/packages/url_launcher/url_launcher_ios/lib/url_launcher_ios.dart @@ -141,6 +141,8 @@ class UrlLauncherIOS extends UrlLauncherPlatform { throw _failedSafariViewControllerLoadException(url); case InAppLoadResult.invalidUrl: throw _invalidUrlException(); + case InAppLoadResult.dismissed: + return false; } } diff --git a/packages/url_launcher/url_launcher_ios/pigeons/messages.dart b/packages/url_launcher/url_launcher_ios/pigeons/messages.dart index 20ecab2b8a1..998970c0ca5 100644 --- a/packages/url_launcher/url_launcher_ios/pigeons/messages.dart +++ b/packages/url_launcher/url_launcher_ios/pigeons/messages.dart @@ -27,11 +27,14 @@ enum InAppLoadResult { /// The URL was successfully loaded. success, - /// The URL did not load successfully (or the user closed the view controller before it loaded). + /// The URL did not load successfully. failedToLoad, /// The URL could not be launched because it is invalid. invalidUrl, + + /// The controller was closed before loading. + dismissed, } @HostApi()