Skip to content

Commit

Permalink
Merge pull request #3 from saasquatch/share-links
Browse files Browse the repository at this point in the history
Implement WKUIDelegate for handling share links and add CHANGELOG
  • Loading branch information
johanventer authored May 18, 2021
2 parents c4daa74 + 6db67a5 commit a510b83
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 2 deletions.
20 changes: 20 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
# Changelog
All notable changes to this project will be documented in this file.

The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## [Unreleased]

## [1.0.0-beta.1] - 2021-05-12
### Added
- WKUIDelegate method implementation to open share links in default browser.

## [1.0.0-beta] - 2021-05-07
### Added
- Base functionality for rendering a widget in a managed WKWebView.
- SaaSquatch API methods for `graphql`, `renderWidget`, `upsertWidget`, `logUserEvent`, `pushWidgetLoadedAnalyticEvent`, and `pushWidgetSharedAnalyticEvent`.

[Unreleased]: https://github.com/saasquatch/squatch-ios/compare/v1.0.0-beta.1...HEAD
[1.0.0-beta.1]: https://github.com/saasquatch/squatch-ios/compare/v1.0.0-beta...v1.0.0-beta.1
[1.0.0-beta]: https://github.com/saasquatch/squatch-ios/releases/tag/v1.0.0-beta
2 changes: 1 addition & 1 deletion Example/Example/ContentView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ class WebViewController: UIViewController {
super.viewDidLoad()

let jwt = "<jwt>"

do {
let input = try WidgetUpsertInput.Builder()
.setUserInputWithUserJwt(jwt)
Expand Down
15 changes: 14 additions & 1 deletion Sources/SaaSquatchWebView/SaaSquatchWebView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import SwiftyJSON
import WebKit
import SaaSquatch

public class SaaSquatchWebView: WKWebView {
public class SaaSquatchWebView: WKWebView, WKUIDelegate {
public var client: SaaSquatchClient?

/**
Expand Down Expand Up @@ -85,6 +85,7 @@ public class SaaSquatchWebView: WKWebView {

private func setWebViewContent(html: String) {
DispatchQueue.main.async {
self.uiDelegate = self
let htmlWithMeta = html.replacingOccurrences(of: "</head>", with: "<meta name=\"viewport\" content=\"initial-scale=1.0\" /></head>")
self.loadHTMLString(htmlWithMeta, baseURL: URL(string: "https://fast.ssqt.io"))
}
Expand Down Expand Up @@ -114,6 +115,18 @@ public class SaaSquatchWebView: WKWebView {
}
}
}

public func webView(_ webView: WKWebView,
createWebViewWith configuration: WKWebViewConfiguration,
for navigationAction: WKNavigationAction,
windowFeatures: WKWindowFeatures) -> WKWebView? {
if let url = navigationAction.request.url, navigationAction.targetFrame == nil {
if url.scheme == "http" || url.scheme == "https" || url.scheme == "mailto" {
UIApplication.shared.open(url)
}
}
return nil
}
}

let ERROR_HTML_TEMPLATE = """
Expand Down

0 comments on commit a510b83

Please sign in to comment.