diff --git a/OSInAppBrowserLib.podspec b/OSInAppBrowserLib.podspec index 6928ff0..34e2747 100644 --- a/OSInAppBrowserLib.podspec +++ b/OSInAppBrowserLib.podspec @@ -22,8 +22,9 @@ Pod::Spec.new do |spec| spec.author = { 'OutSystems Mobile Ecosystem' => 'rd.mobileecosystem.team@outsystems.com' } spec.source = { :http => "https://github.com/OutSystems/OSInAppBrowserLib-iOS/releases/download/#{spec.version}/OSInAppBrowserLib.zip", :type => "zip" } + spec.source_files = "OSInAppBrowserLib/**/*" spec.vendored_frameworks = "OSInAppBrowserLib.xcframework" spec.ios.deployment_target = '13.0' spec.swift_versions = ['5.0', '5.1', '5.2', '5.3', '5.4', '5.5', '5.6', '5.7', '5.8', '5.9'] -end \ No newline at end of file +end diff --git a/OSInAppBrowserLib/RouterAdapters/OSIABApplicationRouterAdapter.swift b/OSInAppBrowserLib/RouterAdapters/OSIABApplicationRouterAdapter.swift index 73b491b..ef0fbae 100644 --- a/OSInAppBrowserLib/RouterAdapters/OSIABApplicationRouterAdapter.swift +++ b/OSInAppBrowserLib/RouterAdapters/OSIABApplicationRouterAdapter.swift @@ -4,19 +4,16 @@ import UIKit /// This is implemented by the `UIApplication` object that can be used as an External Browser. public protocol OSIABApplicationDelegate: AnyObject { func canOpenURL(_ url: URL) -> Bool - func open(_ url: URL, options: [UIApplication.OpenExternalURLOptionsKey: Any], completionHandler completion: ((Bool) -> Void)?) + func open(_ url: URL, completionHandler completion: ((Bool) -> Void)?) } -/// Provide a default implementations that abstracts the options parameter. -extension OSIABApplicationDelegate { - func open(_ url: URL, options: [UIApplication.OpenExternalURLOptionsKey: Any] = [:], completionHandler completion: ((Bool) -> Void)?) { - self.open(url, options: options, completionHandler: completion) +/// Make `UIApplication` conform to the `OSIABApplicationDelegate` protocol. +extension UIApplication: OSIABApplicationDelegate { + func open(_ url: URL, completionHandler completion: ((Bool) -> Void)?) { + self.open(url, options: [:], completionHandler: completion) } } -/// Make `UIApplication` conform to the `OSIABApplicationDelegate` protocol. -extension UIApplication: OSIABApplicationDelegate {} - /// Adapter that makes the required calls so that an `OSIABApplicationDelegate` implementation can perform the External Browser routing. public class OSIABApplicationRouterAdapter: OSIABRouter { public typealias ReturnType = Bool diff --git a/OSInAppBrowserLib/WebView/OSIABWebViewCallbackHandler.swift b/OSInAppBrowserLib/WebView/OSIABWebViewCallbackHandler.swift index a2a8552..cb6e3f3 100644 --- a/OSInAppBrowserLib/WebView/OSIABWebViewCallbackHandler.swift +++ b/OSInAppBrowserLib/WebView/OSIABWebViewCallbackHandler.swift @@ -10,7 +10,9 @@ public struct OSIABWebViewCallbackHandler { let onBrowserPageLoad: () -> Void /// Callback to trigger when the browser is closed. The boolean arguments indicates if the browser was already close or still needs to be. let onBrowserClosed: (Bool) -> Void - + /// Callback to trigger when the browser finishes navigation. The argument is the current URL. + let onBrowserPageNavigationCompleted: (String?) -> Void + /// Constructor method. /// - Parameters: /// - onDelegateURL: Callback to trigger when the an URL needs to be delegates to its callers. @@ -21,11 +23,13 @@ public struct OSIABWebViewCallbackHandler { onDelegateURL: @escaping (URL) -> Void, onDelegateAlertController: @escaping (UIAlertController) -> Void, onBrowserPageLoad: @escaping () -> Void, - onBrowserClosed: @escaping (Bool) -> Void // boolean indicates if the browser is already closed. + onBrowserClosed: @escaping (Bool) -> Void, // boolean indicates if the browser is already closed. + onBrowserPageNavigationCompleted: @escaping (String?) -> Void ) { self.onDelegateURL = onDelegateURL self.onDelegateAlertController = onDelegateAlertController self.onBrowserPageLoad = onBrowserPageLoad self.onBrowserClosed = onBrowserClosed + self.onBrowserPageNavigationCompleted = onBrowserPageNavigationCompleted } } diff --git a/OSInAppBrowserLib/WebView/OSIABWebViewModel.swift b/OSInAppBrowserLib/WebView/OSIABWebViewModel.swift index 079b752..da289f8 100644 --- a/OSInAppBrowserLib/WebView/OSIABWebViewModel.swift +++ b/OSInAppBrowserLib/WebView/OSIABWebViewModel.swift @@ -182,6 +182,8 @@ extension OSIABWebViewModel: WKNavigationDelegate { if !self.firstLoadDone { self.callbackHandler.onBrowserPageLoad() self.firstLoadDone = true + } else { + self.callbackHandler.onBrowserPageNavigationCompleted(url.absoluteString) } error = nil } diff --git a/OSInAppBrowserLib/WebView/Views/OSIABWebView.swift b/OSInAppBrowserLib/WebView/Views/OSIABWebView.swift index 100fd44..ffa56e9 100644 --- a/OSInAppBrowserLib/WebView/Views/OSIABWebView.swift +++ b/OSInAppBrowserLib/WebView/Views/OSIABWebView.swift @@ -96,7 +96,8 @@ private extension OSIABWebViewModel { onDelegateURL: { _ in }, onDelegateAlertController: { _ in }, onBrowserPageLoad: {}, - onBrowserClosed: onBrowserClosed + onBrowserClosed: onBrowserClosed, + onBrowserPageNavigationCompleted: { _ in } ) ) } diff --git a/OSInAppBrowserLib/WebView/Views/OSIABWebView13WrapperView.swift b/OSInAppBrowserLib/WebView/Views/OSIABWebView13WrapperView.swift index abfd280..fa512d3 100644 --- a/OSInAppBrowserLib/WebView/Views/OSIABWebView13WrapperView.swift +++ b/OSInAppBrowserLib/WebView/Views/OSIABWebView13WrapperView.swift @@ -58,7 +58,8 @@ private extension OSIABWebViewModel { onDelegateURL: { _ in }, onDelegateAlertController: { _ in }, onBrowserPageLoad: {}, - onBrowserClosed: { _ in } + onBrowserClosed: { _ in }, + onBrowserPageNavigationCompleted: { _ in } ) ) } @@ -73,7 +74,8 @@ private extension OSIABWebViewModel { onDelegateURL: { _ in }, onDelegateAlertController: { _ in }, onBrowserPageLoad: {}, - onBrowserClosed: { _ in } + onBrowserClosed: { _ in }, + onBrowserPageNavigationCompleted: { _ in } ) ) } diff --git a/OSInAppBrowserLib/WebView/Views/OSIABWebViewWrapperView.swift b/OSInAppBrowserLib/WebView/Views/OSIABWebViewWrapperView.swift index ed96d85..1240315 100644 --- a/OSInAppBrowserLib/WebView/Views/OSIABWebViewWrapperView.swift +++ b/OSInAppBrowserLib/WebView/Views/OSIABWebViewWrapperView.swift @@ -35,7 +35,8 @@ private extension OSIABWebViewModel { onDelegateURL: { _ in }, onDelegateAlertController: { _ in }, onBrowserPageLoad: {}, - onBrowserClosed: { _ in } + onBrowserClosed: { _ in }, + onBrowserPageNavigationCompleted: { _ in } ) ) } @@ -50,7 +51,8 @@ private extension OSIABWebViewModel { onDelegateURL: { _ in }, onDelegateAlertController: { _ in }, onBrowserPageLoad: {}, - onBrowserClosed: { _ in } + onBrowserClosed: { _ in }, + onBrowserPageNavigationCompleted: { _ in } ) ) } diff --git a/OSInAppBrowserLibTests/OSIABViewModelTests.swift b/OSInAppBrowserLibTests/OSIABViewModelTests.swift index 8730049..15f0f12 100644 --- a/OSInAppBrowserLibTests/OSIABViewModelTests.swift +++ b/OSInAppBrowserLibTests/OSIABViewModelTests.swift @@ -181,6 +181,20 @@ final class OSIABViewModelTests: XCTestCase { XCTAssertEqual(resultAction, .allow) } + func test_navigateToNewPage_onBrowserPageNavigationCompletedEventShouldBeTrigged() { + var result: String? = nil + let expectation = self.expectation(description: "Trigger onBrowserPageNavigationCompleted Event") + + let sut = makeSUT(url, onBrowserPageNavigationCompleted: { data in + result = data + expectation.fulfill() + }) + sut.webView(sut.webView, didFinish: nil) + sut.webView(sut.webView, didFinish: nil) + waitForExpectations(timeout: 1) + XCTAssertEqual(url.absoluteString, result) + } + // MARK: Browser Page Load Event Tests func test_navigateToURL_whenFinished_triggerPageLoadEventOnFirstTime() { @@ -275,7 +289,8 @@ private extension OSIABViewModelTests { onDelegateURL: @escaping (URL) -> Void = { _ in }, onDelegateAlertController: @escaping (UIAlertController) -> Void = { _ in }, onBrowserPageLoad: @escaping () -> Void = {}, - onBrowserClosed: @escaping (Bool) -> Void = { _ in } + onBrowserClosed: @escaping (Bool) -> Void = { _ in }, + onBrowserPageNavigationCompleted: @escaping (String?) -> Void = { _ in } ) -> OSIABWebViewModel { let configurationModel = OSIABWebViewConfigurationModel( mediaTypesRequiringUserActionForPlayback, ignoresViewportScaleLimits, allowsInlineMediaPlayback, surpressesIncrementalRendering @@ -297,7 +312,8 @@ private extension OSIABViewModelTests { onDelegateURL: onDelegateURL, onDelegateAlertController: onDelegateAlertController, onBrowserPageLoad: onBrowserPageLoad, - onBrowserClosed: onBrowserClosed + onBrowserClosed: onBrowserClosed, + onBrowserPageNavigationCompleted: onBrowserPageNavigationCompleted ) ) } diff --git a/OSInAppBrowserLibTests/OSIABWebViewRouterAdapterTests.swift b/OSInAppBrowserLibTests/OSIABWebViewRouterAdapterTests.swift index 6788728..8bf11c5 100644 --- a/OSInAppBrowserLibTests/OSIABWebViewRouterAdapterTests.swift +++ b/OSInAppBrowserLibTests/OSIABWebViewRouterAdapterTests.swift @@ -141,7 +141,8 @@ private extension OSIABWebViewRouterAdapterTests { onDelegateURL: { _ in }, onDelegateAlertController: { _ in }, onBrowserPageLoad: {}, - onBrowserClosed: onBrowserClosed + onBrowserClosed: onBrowserClosed, + onBrowserPageNavigationCompleted: { _ in } ) ) }