Skip to content
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

🦋 Fixed sign-in block and web block functionality #30

Merged
merged 2 commits into from
Jun 3, 2021
Merged
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
2 changes: 1 addition & 1 deletion AdaEmbedFramework.podspec
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
Pod::Spec.new do |spec|

spec.name = "AdaEmbedFramework"
spec.version = "1.3.5"
spec.version = "1.3.6"
spec.summary = "Embed the Ada Support SDK in your app."
spec.description = "Use the Ada Support SDK to inject the Ada support experience into your app. Visit https://ada.support to learn more."
spec.homepage = "https://github.com/AdaSupport/ios-sdk"
Expand Down
67 changes: 43 additions & 24 deletions EmbedFramework/AdaWebHost.swift
Original file line number Diff line number Diff line change
Expand Up @@ -203,11 +203,15 @@ public class AdaWebHost: NSObject {

extension AdaWebHost {
private func setupWebView() {
let wkPreferences = WKPreferences()
wkPreferences.javaScriptCanOpenWindowsAutomatically = true
wkPreferences.javaScriptEnabled = true
let configuration = WKWebViewConfiguration()
let userContentController = WKUserContentController()
let clusterString = cluster.isEmpty ? "" : "\(cluster)."
configuration.userContentController = userContentController
configuration.mediaTypesRequiringUserActionForPlayback = []
configuration.preferences = wkPreferences
webView = WKWebView(frame: .zero, configuration: configuration)
guard let webView = webView else { return }
webView.scrollView.isScrollEnabled = false
Expand Down Expand Up @@ -239,33 +243,48 @@ extension AdaWebHost: WKNavigationDelegate, WKUIDelegate {
self.hasError = true
self.webViewLoadingErrorCallback?(AdaWebHostError.WebViewFailedToLoad)
}
public func webView(_ webView: WKWebView, decidePolicyFor navigationAction: WKNavigationAction, decisionHandler: @escaping (WKNavigationActionPolicy) -> Swift.Void) {

// Shared function to handle opening of urls
public func openUrl(webView: WKWebView, url: URL) -> Swift.Void {
let httpSchemes = ["http", "https"]

let urlScheme = url.scheme
// Handle opening universal links within the host App
// This requires the appScheme argument to work
if urlScheme == self.appScheme {
guard let presentingVC = findViewController(from: webView) else { return }
presentingVC.dismiss(animated: true) {
let shared = UIApplication.shared
if shared.canOpenURL(url) {
shared.open(url, options: [:], completionHandler: nil)
}
}
// Only open links in in-app WebView if URL uses HTTP(S) scheme, and the openWebLinksInSafari option is false
// This is where SUP-43 is likely crashing
} else if self.openWebLinksInSafari == false && httpSchemes.contains(urlScheme ?? "") {
let sfVC = SFSafariViewController(url: url)
guard let presentingVC = findViewController(from: webView) else { return }
presentingVC.present(sfVC, animated: true, completion: nil)
} else {
let shared = UIApplication.shared
if shared.canOpenURL(url) {
shared.open(url, options: [:], completionHandler: nil)
}
}
}

// Used for weblinks and signon (handling window.open js call)
public func webView(_ webView: WKWebView, createWebViewWith configuration: WKWebViewConfiguration, for navigationAction: WKNavigationAction, windowFeatures: WKWindowFeatures) -> WKWebView? {
if let url = navigationAction.request.url {
openUrl(webView: webView, url: url)
}
return nil
}

// Used for processing all other navigation
public func webView(_ webView: WKWebView, decidePolicyFor navigationAction: WKNavigationAction, decisionHandler: @escaping (WKNavigationActionPolicy) -> Swift.Void) {
if navigationAction.navigationType == WKNavigationType.linkActivated {
if let url = navigationAction.request.url {
let urlScheme = url.scheme
// Handle opening universal links within the host App
// This requires the appScheme argument to work
if urlScheme == self.appScheme {
guard let presentingVC = findViewController(from: webView) else { return }
presentingVC.dismiss(animated: true) {
let shared = UIApplication.shared
if shared.canOpenURL(url) {
shared.open(url, options: [:], completionHandler: nil)
}
}
// Only open links in in-app WebView if URL uses HTTP(S) scheme, and the openWebLinksInSafari option is false
} else if self.openWebLinksInSafari == false && httpSchemes.contains(urlScheme ?? "") {
let sfVC = SFSafariViewController(url: url)
guard let presentingVC = findViewController(from: webView) else { return }
presentingVC.present(sfVC, animated: true, completion: nil)
} else {
let shared = UIApplication.shared
if shared.canOpenURL(url) {
shared.open(url, options: [:], completionHandler: nil)
}
}
openUrl(webView: webView, url: url)
}
decisionHandler(.cancel)
}
Expand Down