|
1 | 1 | import UIKit |
2 | 2 |
|
3 | | -/// Protocol to be implemented by the objects that can handle opening URLs. |
4 | | -/// This is implemented by the `UIApplication` object that can be used as an External Browser. |
5 | | -public protocol OSIABApplicationDelegate: AnyObject { |
6 | | - func canOpenURL(_ url: URL) -> Bool |
7 | | - func open(_ url: URL, options: [UIApplication.OpenExternalURLOptionsKey: Any], completionHandler completion: ((Bool) -> Void)?) |
8 | | -} |
9 | | - |
10 | | -/// Provide a default implementations that abstracts the options parameter. |
11 | | -extension OSIABApplicationDelegate { |
12 | | - public func open(_ url: URL, options: [UIApplication.OpenExternalURLOptionsKey: Any] = [:], completionHandler completion: ((Bool) -> Void)?) { |
13 | | - self.open(url, options: options, completionHandler: completion) |
14 | | - } |
15 | | -} |
16 | | - |
17 | | -/// Make `UIApplication` conform to the `OSIABApplicationDelegate` protocol. |
18 | | -extension UIApplication: OSIABApplicationDelegate {} |
19 | | - |
20 | | -/// Adapter that makes the required calls so that an `OSIABApplicationDelegate` implementation can perform the External Browser routing. |
| 3 | +/// Adapter that makes the required calls so that can perform the External Browser routing. |
21 | 4 | public class OSIABApplicationRouterAdapter: OSIABRouter { |
22 | 5 | public typealias ReturnType = Bool |
23 | | - |
24 | | - /// The object that will performing the URL opening. |
25 | | - private let application: OSIABApplicationDelegate |
26 | | - |
| 6 | + |
27 | 7 | /// Constructor method. |
28 | | - /// - Parameter application: The object that will performing the URL opening. |
29 | | - public init(_ application: OSIABApplicationDelegate) { |
30 | | - self.application = application |
31 | | - } |
| 8 | + public init() {} |
32 | 9 |
|
33 | 10 | public func handleOpen(_ url: URL, _ completionHandler: @escaping (ReturnType) -> Void) { |
34 | | - guard self.application.canOpenURL(url) else { return completionHandler(false) } |
35 | | - self.application.open(url, completionHandler: completionHandler) |
| 11 | + guard UIApplication.shared.canOpenURL(url) else { return completionHandler(false) } |
| 12 | + UIApplication.shared.open(url, completionHandler: completionHandler) |
36 | 13 | } |
37 | 14 | } |
0 commit comments