Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
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
3 changes: 2 additions & 1 deletion OSInAppBrowserLib.podspec
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,9 @@ Pod::Spec.new do |spec|
spec.author = { 'OutSystems Mobile Ecosystem' => '[email protected]' }

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
end
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
8 changes: 6 additions & 2 deletions OSInAppBrowserLib/WebView/OSIABWebViewCallbackHandler.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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
}
}
2 changes: 2 additions & 0 deletions OSInAppBrowserLib/WebView/OSIABWebViewModel.swift
Original file line number Diff line number Diff line change
Expand Up @@ -182,6 +182,8 @@ extension OSIABWebViewModel: WKNavigationDelegate {
if !self.firstLoadDone {
self.callbackHandler.onBrowserPageLoad()
self.firstLoadDone = true
} else {
self.callbackHandler.onBrowserPageNavigationCompleted(url.absoluteString)
}
error = nil
}
Expand Down
3 changes: 2 additions & 1 deletion OSInAppBrowserLib/WebView/Views/OSIABWebView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,8 @@ private extension OSIABWebViewModel {
onDelegateURL: { _ in },
onDelegateAlertController: { _ in },
onBrowserPageLoad: {},
onBrowserClosed: onBrowserClosed
onBrowserClosed: onBrowserClosed,
onBrowserPageNavigationCompleted: { _ in }
)
)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,8 @@ private extension OSIABWebViewModel {
onDelegateURL: { _ in },
onDelegateAlertController: { _ in },
onBrowserPageLoad: {},
onBrowserClosed: { _ in }
onBrowserClosed: { _ in },
onBrowserPageNavigationCompleted: { _ in }
)
)
}
Expand All @@ -73,7 +74,8 @@ private extension OSIABWebViewModel {
onDelegateURL: { _ in },
onDelegateAlertController: { _ in },
onBrowserPageLoad: {},
onBrowserClosed: { _ in }
onBrowserClosed: { _ in },
onBrowserPageNavigationCompleted: { _ in }
)
)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,8 @@ private extension OSIABWebViewModel {
onDelegateURL: { _ in },
onDelegateAlertController: { _ in },
onBrowserPageLoad: {},
onBrowserClosed: { _ in }
onBrowserClosed: { _ in },
onBrowserPageNavigationCompleted: { _ in }
)
)
}
Expand All @@ -50,7 +51,8 @@ private extension OSIABWebViewModel {
onDelegateURL: { _ in },
onDelegateAlertController: { _ in },
onBrowserPageLoad: {},
onBrowserClosed: { _ in }
onBrowserClosed: { _ in },
onBrowserPageNavigationCompleted: { _ in }
)
)
}
Expand Down
20 changes: 18 additions & 2 deletions OSInAppBrowserLibTests/OSIABViewModelTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down Expand Up @@ -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
Expand All @@ -297,7 +312,8 @@ private extension OSIABViewModelTests {
onDelegateURL: onDelegateURL,
onDelegateAlertController: onDelegateAlertController,
onBrowserPageLoad: onBrowserPageLoad,
onBrowserClosed: onBrowserClosed
onBrowserClosed: onBrowserClosed,
onBrowserPageNavigationCompleted: onBrowserPageNavigationCompleted
)
)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,8 @@ private extension OSIABWebViewRouterAdapterTests {
onDelegateURL: { _ in },
onDelegateAlertController: { _ in },
onBrowserPageLoad: {},
onBrowserClosed: onBrowserClosed
onBrowserClosed: onBrowserClosed,
onBrowserPageNavigationCompleted: { _ in }
)
)
}
Expand Down
Loading