Skip to content

Added a delegate to AdaWebHost to let apps have control over handling their Universal Link URLs #82

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
4 changes: 4 additions & 0 deletions AdaEmbedFramework.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
49C73568226F99FE00D22E4B /* EmbedFrameworkTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 49C73567226F99FE00D22E4B /* EmbedFrameworkTests.swift */; };
49C7356A226F99FE00D22E4B /* EmbedFramework.h in Headers */ = {isa = PBXBuildFile; fileRef = 49C7355C226F99FE00D22E4B /* EmbedFramework.h */; settings = {ATTRIBUTES = (Public, ); }; };
4D62BE845FB815D5E41D3EFA /* Pods_AdaEmbedFramework_AdaEmbedFrameworkTests.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 8EDF945E44BBD03973DD86FC /* Pods_AdaEmbedFramework_AdaEmbedFrameworkTests.framework */; };
59B38CC1298DBD380086A2B4 /* AdaWebHost+Delegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = 59B38CC0298DBD380086A2B4 /* AdaWebHost+Delegate.swift */; };
936ED6B7228F438800796860 /* AdaWebHostViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 936ED6B6228F438800796860 /* AdaWebHostViewController.swift */; };
936ED6B9228F471800796860 /* AdaWebHostViewController.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 936ED6B8228F471800796860 /* AdaWebHostViewController.storyboard */; };
938BBFD122A93F1B000012A9 /* Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = 938BBFD022A93F1B000012A9 /* Assets.xcassets */; };
Expand Down Expand Up @@ -139,6 +140,7 @@
49C73562226F99FE00D22E4B /* AdaEmbedFrameworkTests.xctest */ = {isa = PBXFileReference; explicitFileType = wrapper.cfbundle; includeInIndex = 0; path = AdaEmbedFrameworkTests.xctest; sourceTree = BUILT_PRODUCTS_DIR; };
49C73567226F99FE00D22E4B /* EmbedFrameworkTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = EmbedFrameworkTests.swift; sourceTree = "<group>"; };
49C73569226F99FE00D22E4B /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = "<group>"; };
59B38CC0298DBD380086A2B4 /* AdaWebHost+Delegate.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "AdaWebHost+Delegate.swift"; sourceTree = "<group>"; };
88E7E55B2981D30700F08C85 /* ExampleAppCarthage.xcodeproj */ = {isa = PBXFileReference; lastKnownFileType = "wrapper.pb-project"; name = ExampleAppCarthage.xcodeproj; path = ExampleAppCarthage/ExampleAppCarthage.xcodeproj; sourceTree = "<group>"; };
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>"; };
8EDF945E44BBD03973DD86FC /* Pods_AdaEmbedFramework_AdaEmbedFrameworkTests.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = Pods_AdaEmbedFramework_AdaEmbedFrameworkTests.framework; sourceTree = BUILT_PRODUCTS_DIR; };
Expand Down Expand Up @@ -349,6 +351,7 @@
938BBFD222A94100000012A9 /* OfflineViewController.swift */,
938BBFD022A93F1B000012A9 /* Assets.xcassets */,
938BBFD422A94304000012A9 /* Reachability.swift */,
59B38CC0298DBD380086A2B4 /* AdaWebHost+Delegate.swift */,
);
path = EmbedFramework;
sourceTree = "<group>";
Expand Down Expand Up @@ -597,6 +600,7 @@
files = (
938BBFD322A94100000012A9 /* OfflineViewController.swift in Sources */,
936ED6B7228F438800796860 /* AdaWebHostViewController.swift in Sources */,
59B38CC1298DBD380086A2B4 /* AdaWebHost+Delegate.swift in Sources */,
938BBFD522A94304000012A9 /* Reachability.swift in Sources */,
93A79798228C871200499BF9 /* AdaWebHost.swift in Sources */,
);
Expand Down
13 changes: 13 additions & 0 deletions EmbedFramework/AdaWebHost+Delegate.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import Foundation

public protocol AdaWebHostDelegate: AnyObject {
/// Use this function to handle urls inside the app.
/// Should return false if app will handle the url.
func adaWebHost(_ host: AdaWebHost, shouldOpenUrl url: URL) -> Bool
}

public extension AdaWebHostDelegate {
func adaWebHost(_ host: AdaWebHost, shouldOpenUrl url: URL) -> Bool {
true
}
}
6 changes: 5 additions & 1 deletion EmbedFramework/AdaWebHost.swift
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ public class AdaWebHost: NSObject {
public var greeting = ""
public var deviceToken = ""
public var webViewTimeout = 30.0

public weak var delegate: AdaWebHostDelegate?

/// Metafields can be passed in during init; use `setMetaFields()` and `setSensitiveMetafields()`
/// to send values in at runtime
Expand Down Expand Up @@ -434,6 +434,10 @@ extension AdaWebHost: WKNavigationDelegate, WKUIDelegate, WKDownloadDelegate {

// Shared function to handle opening of urls
public func openUrl(webView: WKWebView, url: URL) -> Swift.Void {
guard let delegate,
delegate.adaWebHost(self, shouldOpenUrl: url)
else { return }

let httpSchemes = ["http", "https"]
let urlScheme = url.scheme
// Handle opening universal links within the host App
Expand Down