Skip to content

Commit 2142737

Browse files
Added a delegate to AdaWebHost to let apps have control over handling their Universal Link URLs
1 parent 99f2a41 commit 2142737

File tree

3 files changed

+22
-1
lines changed

3 files changed

+22
-1
lines changed

Diff for: AdaEmbedFramework.xcodeproj/project.pbxproj

+4
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
49C73568226F99FE00D22E4B /* EmbedFrameworkTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 49C73567226F99FE00D22E4B /* EmbedFrameworkTests.swift */; };
1313
49C7356A226F99FE00D22E4B /* EmbedFramework.h in Headers */ = {isa = PBXBuildFile; fileRef = 49C7355C226F99FE00D22E4B /* EmbedFramework.h */; settings = {ATTRIBUTES = (Public, ); }; };
1414
4D62BE845FB815D5E41D3EFA /* Pods_AdaEmbedFramework_AdaEmbedFrameworkTests.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 8EDF945E44BBD03973DD86FC /* Pods_AdaEmbedFramework_AdaEmbedFrameworkTests.framework */; };
15+
59B38CC1298DBD380086A2B4 /* AdaWebHost+Delegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = 59B38CC0298DBD380086A2B4 /* AdaWebHost+Delegate.swift */; };
1516
936ED6B7228F438800796860 /* AdaWebHostViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 936ED6B6228F438800796860 /* AdaWebHostViewController.swift */; };
1617
936ED6B9228F471800796860 /* AdaWebHostViewController.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 936ED6B8228F471800796860 /* AdaWebHostViewController.storyboard */; };
1718
938BBFD122A93F1B000012A9 /* Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = 938BBFD022A93F1B000012A9 /* Assets.xcassets */; };
@@ -139,6 +140,7 @@
139140
49C73562226F99FE00D22E4B /* AdaEmbedFrameworkTests.xctest */ = {isa = PBXFileReference; explicitFileType = wrapper.cfbundle; includeInIndex = 0; path = AdaEmbedFrameworkTests.xctest; sourceTree = BUILT_PRODUCTS_DIR; };
140141
49C73567226F99FE00D22E4B /* EmbedFrameworkTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = EmbedFrameworkTests.swift; sourceTree = "<group>"; };
141142
49C73569226F99FE00D22E4B /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = "<group>"; };
143+
59B38CC0298DBD380086A2B4 /* AdaWebHost+Delegate.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "AdaWebHost+Delegate.swift"; sourceTree = "<group>"; };
142144
88E7E55B2981D30700F08C85 /* ExampleAppCarthage.xcodeproj */ = {isa = PBXFileReference; lastKnownFileType = "wrapper.pb-project"; name = ExampleAppCarthage.xcodeproj; path = ExampleAppCarthage/ExampleAppCarthage.xcodeproj; sourceTree = "<group>"; };
143145
8D84564760E66C5DB8D387D2 /* Pods-ExampleApp.release.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-ExampleApp.release.xcconfig"; path = "Target Support Files/Pods-ExampleApp/Pods-ExampleApp.release.xcconfig"; sourceTree = "<group>"; };
144146
8EDF945E44BBD03973DD86FC /* Pods_AdaEmbedFramework_AdaEmbedFrameworkTests.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = Pods_AdaEmbedFramework_AdaEmbedFrameworkTests.framework; sourceTree = BUILT_PRODUCTS_DIR; };
@@ -349,6 +351,7 @@
349351
938BBFD222A94100000012A9 /* OfflineViewController.swift */,
350352
938BBFD022A93F1B000012A9 /* Assets.xcassets */,
351353
938BBFD422A94304000012A9 /* Reachability.swift */,
354+
59B38CC0298DBD380086A2B4 /* AdaWebHost+Delegate.swift */,
352355
);
353356
path = EmbedFramework;
354357
sourceTree = "<group>";
@@ -597,6 +600,7 @@
597600
files = (
598601
938BBFD322A94100000012A9 /* OfflineViewController.swift in Sources */,
599602
936ED6B7228F438800796860 /* AdaWebHostViewController.swift in Sources */,
603+
59B38CC1298DBD380086A2B4 /* AdaWebHost+Delegate.swift in Sources */,
600604
938BBFD522A94304000012A9 /* Reachability.swift in Sources */,
601605
93A79798228C871200499BF9 /* AdaWebHost.swift in Sources */,
602606
);

Diff for: EmbedFramework/AdaWebHost+Delegate.swift

+13
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
import Foundation
2+
3+
public protocol AdaWebHostDelegate: AnyObject {
4+
/// Use this function to handle urls inside the app.
5+
/// Should return false if app will handle the url.
6+
func adaWebHost(_ host: AdaWebHost, shouldOpenUrl url: URL) -> Bool
7+
}
8+
9+
public extension AdaWebHostDelegate {
10+
func adaWebHost(_ host: AdaWebHost, shouldOpenUrl url: URL) -> Bool {
11+
true
12+
}
13+
}

Diff for: EmbedFramework/AdaWebHost.swift

+5-1
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-
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,6 +434,10 @@ 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+
guard let delegate,
438+
delegate.adaWebHost(self, shouldOpenUrl: url)
439+
else { return }
440+
437441
let httpSchemes = ["http", "https"]
438442
let urlScheme = url.scheme
439443
// Handle opening universal links within the host App

0 commit comments

Comments
 (0)