Skip to content

Commit 07766ca

Browse files
Improved syntax
Signed-off-by: Mo Poroushani <[email protected]>
1 parent 5dee801 commit 07766ca

File tree

2 files changed

+7
-14
lines changed

2 files changed

+7
-14
lines changed
Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
import Foundation
22

3-
public protocol AdaWebHostDelegateProtocol: NSObjectProtocol {
3+
public protocol AdaWebHostDelegate: NSObjectProtocol {
44
/// Use this function to handle urls inside the app.
55
/// Should return `nil` if app will handle the url.
6-
func handle(url: URL) -> URL?
6+
func adaWebHost(_ host: AdaWebHost, shouldOpenUrl url: URL) -> Bool
77
}
88

9-
public extension AdaWebHostDelegateProtocol {
10-
func handle(url: URL) -> URL? {
11-
url
9+
public extension AdaWebHostDelegate {
10+
func adaWebHost(_ host: AdaWebHost, shouldOpenUrl url: URL) -> Bool {
11+
true
1212
}
1313
}

EmbedFramework/AdaWebHost.swift

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ public class AdaWebHost: NSObject {
4444
public var greeting = ""
4545
public var deviceToken = ""
4646
public var webViewTimeout = 30.0
47-
public weak var delegate: AdaWebHostDelegateProtocol?
47+
public weak var delegate: AdaWebHostDelegate?
4848

4949
/// Metafields can be passed in during init; use `setMetaFields()` and `setSensitiveMetafields()`
5050
/// to send values in at runtime
@@ -434,14 +434,7 @@ extension AdaWebHost: WKNavigationDelegate, WKUIDelegate, WKDownloadDelegate {
434434

435435
// Shared function to handle opening of urls
436436
public func openUrl(webView: WKWebView, url: URL) -> Swift.Void {
437-
var url = url
438-
if let delegate {
439-
guard let unhandledUrl = delegate.handle(url: url) else {
440-
return
441-
}
442-
443-
url = unhandledUrl
444-
}
437+
guard (delegate?.adaWebHost(self, shouldOpenUrl: url) ?? true) else { return }
445438

446439
let httpSchemes = ["http", "https"]
447440
let urlScheme = url.scheme

0 commit comments

Comments
 (0)