Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
38 commits
Select commit Hold shift + click to select a range
1d5609f
converting url_launcher from objc to swift
chrisdlangham Aug 18, 2023
d5727dd
converting tests to swift
chrisdlangham Aug 22, 2023
c4e55fb
converting tests to swift
chrisdlangham Aug 22, 2023
050d6b3
fixing issue where pigeon and method channels were not setup right
chrisdlangham Aug 22, 2023
5278199
formatting
chrisdlangham Aug 22, 2023
55a345b
reverting unintentional local changes
chrisdlangham Aug 22, 2023
8356d7a
fixing issues with Ui tests
chrisdlangham Aug 22, 2023
120b2d4
formating
chrisdlangham Aug 22, 2023
1316f3c
Merge branch 'main' into coverting-objc-to-swift
chrisdlangham Aug 22, 2023
7bd3553
updating version and change log
chrisdlangham Aug 22, 2023
2741de4
converting tests to swift
chrisdlangham Aug 22, 2023
495de26
converting unit tests to swift
chrisdlangham Aug 23, 2023
c898698
Merge branch 'main' into converting-url-launcher-ios-tests-to-swift
chrisdlangham Aug 23, 2023
6a6c8d5
updating change log
chrisdlangham Aug 23, 2023
254b9af
resolving merge conflicts
chrisdlangham Aug 23, 2023
869f18f
formatting
chrisdlangham Aug 23, 2023
1120baa
making test class final and private
chrisdlangham Aug 29, 2023
9f591e3
resolving merge conflicts
chrisdlangham Sep 13, 2023
13cd002
updated tests and formated pigeon file
chrisdlangham Sep 13, 2023
f8f5f0b
updates changelog
chrisdlangham Sep 13, 2023
827204a
Update CHANGELOG.md
chrisdlangham Sep 14, 2023
30568fd
Merge branch 'main' into coverting-objc-to-swift
chrisdlangham Sep 14, 2023
6b5e4cd
uses latest version of pigeon
chrisdlangham Sep 15, 2023
3651a97
updates change log
chrisdlangham Sep 15, 2023
257b7cc
moves setting up the pigeon api to the register function instead of t…
chrisdlangham Sep 15, 2023
3ee9d96
resolving merge conflicts
chrisdlangham Sep 28, 2023
d90702f
Merge branch 'main' into coverting-objc-to-swift
chrisdlangham Oct 7, 2023
7241d20
adds in missing throws keyword
chrisdlangham Oct 7, 2023
9d578f2
addresses feedback
chrisdlangham Oct 7, 2023
657c011
changes pigeon api to not throw errors, and let the dart side throw e…
chrisdlangham Oct 11, 2023
7a2fac5
Merge branch 'main' into coverting-objc-to-swift
chrisdlangham Oct 19, 2023
4d4f1bb
addresses feedback
chrisdlangham Oct 19, 2023
7b6272f
addressing feedback
chrisdlangham Oct 26, 2023
b91dca7
Merge branch 'main' into coverting-objc-to-swift
stuartmorgan-g Oct 26, 2023
e7e011a
Replace default launcher implementation with conformance extension
stuartmorgan-g Oct 26, 2023
d955ef8
swift-format
stuartmorgan-g Oct 26, 2023
1297683
Rework return enum to have different versions
stuartmorgan-g Oct 26, 2023
43966a0
Improve invalid URL testing
stuartmorgan-g Oct 26, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
addresses feedback
  • Loading branch information
chrisdlangham committed Oct 7, 2023
commit 9d578f2d357ce18112fe160e8308b9b8f05f484d
Original file line number Diff line number Diff line change
Expand Up @@ -41,10 +41,10 @@ final class URLLauncherTests: XCTestCase {
let result = try createPlugin().canLaunchUrl(url: "urls can't have spaces")
XCTAssertFalse(result)
} catch {
let generalError = error as? GeneralError
let generalError = error as? FlutterError
XCTAssertEqual(generalError?.code, "argument_error")
XCTAssertEqual(generalError?.message, "Unable to parse URL")
XCTAssertEqual(generalError?.details, "Provided URL: urls can't have spaces")
XCTAssertEqual(generalError?.details as? String, "Provided URL: urls can't have spaces")
}
}

Expand Down Expand Up @@ -89,10 +89,10 @@ final class URLLauncherTests: XCTestCase {
case .failure(let error):
XCTAssertNotNil(error)

let generalError = error as! GeneralError
XCTAssertEqual(generalError.code, "argument_error")
XCTAssertEqual(generalError.message, "Unable to parse URL")
XCTAssertEqual(generalError.details, "Provided URL: urls can't have spaces")
let generalError = error as? FlutterError
XCTAssertEqual(generalError?.code, "argument_error")
XCTAssertEqual(generalError?.message, "Unable to parse URL")
XCTAssertEqual(generalError?.details as? String, "Provided URL: urls can't have spaces")
}
expectation.fulfill()
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,17 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

/// Protocol for UIApplication methods relating to launching URLs.
///
/// This protocol exists to allow injecting an alternate implementation for testing.
protocol Launcher {
func canOpenURL(_ url: URL) -> Bool
func openURL(
_ url: URL, options: [UIApplication.OpenExternalURLOptionsKey: Any],
completionHandler completion: ((Bool) -> Void)?)
}

/// Default implementation of Launcher, using UIApplication.
final class UIApplicationLauncher: Launcher {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can this simply be an empty extension?

extension UIApplication: Launcher {}

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice! Done.

func canOpenURL(_ url: URL) -> Bool {
UIApplication.shared.canOpenURL(url)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,34 +2,36 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

import Flutter
import SafariServices

typealias OpenInSafariVCResponse = (Result<Bool, Error>) -> Void
typealias OpenInSafariCompletionHandler = (Result<Bool, Error>) -> Void

final class URLLaunchSession: NSObject, SFSafariViewControllerDelegate {

private let completion: OpenInSafariVCResponse
private let completion: OpenInSafariCompletionHandler
private let url: URL
let safari: SFSafariViewController
let safariViewController: SFSafariViewController
var didFinish: (() -> Void)?

init(url: URL, completion: @escaping OpenInSafariVCResponse) {
init(url: URL, completion: @escaping OpenInSafariCompletionHandler) {
self.url = url
self.completion = completion
self.safari = SFSafariViewController(url: url)
self.safariViewController = SFSafariViewController(url: url)
super.init()
self.safari.delegate = self
self.safariViewController.delegate = self
}

func safariViewController(
_ controller: SFSafariViewController, didCompleteInitialLoad didLoadSuccessfully: Bool
) {
if didLoadSuccessfully {
completion(Result.success(true))
completion(.success(true))
} else {
completion(
Result.failure(
GeneralError(code: "Error", message: "Error while launching \(url)", details: nil)))
.failure(
FlutterError(code: "Error", message: "Error while launching \(url)", details: nil))
)
}
}

Expand All @@ -39,6 +41,6 @@ final class URLLaunchSession: NSObject, SFSafariViewControllerDelegate {
}

func close() {
safariViewControllerDidFinish(safari)
safariViewControllerDidFinish(safariViewController)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,12 @@ public final class URLLauncherPlugin: NSObject, FlutterPlugin, UrlLauncherApi {
private var currentSession: URLLaunchSession?
private let launcher: Launcher

var topViewController: UIViewController? {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should this be private?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

hmmm, what's the diff between this func, and the one in UIViewController extension below?

// TODO(stuartmorgan) Provide a non-deprecated codepath. See
// https://github.com/flutter/flutter/issues/104117
UIApplication.shared.keyWindow?.rootViewController?.topViewController
}

init(launcher: Launcher = UIApplicationLauncher()) {
self.launcher = launcher
}
Expand Down Expand Up @@ -47,39 +53,33 @@ public final class URLLauncherPlugin: NSObject, FlutterPlugin, UrlLauncherApi {
return
}

currentSession = URLLaunchSession(url: url, completion: completion)
guard let session = currentSession else { return }
let session = URLLaunchSession(url: url, completion: completion)
currentSession = session

session.didFinish = { [weak self] in
self?.currentSession = nil
}
topViewController?.present(session.safari, animated: true, completion: nil)
topViewController?.present(session.safariViewController, animated: true, completion: nil)
}

func closeSafariViewController() throws {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why is this throwing?

currentSession?.close()
}

var topViewController: UIViewController? {
// TODO(stuartmorgan) Provide a non-deprecated codepath. See
// https://github.com/flutter/flutter/issues/104117
UIApplication.shared.keyWindow?.rootViewController?.topViewController
}

/**
* Creates an error for an invalid URL string.
*
* @param url The invalid URL string
* @return The error to return
*/
func invalidURLError(for url: String) -> Error {
GeneralError(
FlutterError(
code: "argument_error", message: "Unable to parse URL", details: "Provided URL: \(url)")
}
}

/// This method recursively iterate through the view hierarchy
/// to return the top most view controller.
/// This method recursively iterates through the view hierarchy
/// to return the top-most view controller.
///
/// It supports the following scenarios:
///
Expand All @@ -104,14 +104,4 @@ extension UIViewController {
}
}

class GeneralError: Error {
let code: String
let message: String
let details: String?

init(code: String, message: String, details: String? = nil) {
self.code = code
self.message = message
self.details = details
}
}
extension FlutterError: Error {}