Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
//
// ViewController.swift
// map-test
//
// Created by Trevor Starick on 2019-06-18.
// Copyright © 2019 Trevor Starick. All rights reserved.
//
import UIKit
import WebKit
import SafariServices
class ViewController: UIViewController, WKUIDelegate, WKNavigationDelegate {
var webView: WKWebView!
// uses SFSafariViewController to open a new Safari view to load the URL in
func loadLink(_ link: URL) {
let config = SFSafariViewController.Configuration()
config.entersReaderIfAvailable = false
let vc = SFSafariViewController(url: link, configuration: config)
present(vc, animated: true)
}
func webView(_ webView: WKWebView, decidePolicyFor navigationAction: WKNavigationAction, decisionHandler: @escaping (WKNavigationActionPolicy) -> Void) {
// allows for all URLs to be loaded
decisionHandler(.allow)
}
func webView(_ webView: WKWebView, createWebViewWith configuration: WKWebViewConfiguration, for navigationAction: WKNavigationAction, windowFeatures: WKWindowFeatures) -> WKWebView? {
// as long as the navigationAction contains a URL, use loadLink() to load the URL
if((navigationAction.request.url) != nil) {
loadLink(navigationAction.request.url!);
}
return nil;
}
override func loadView() {
let webConfiguration = WKWebViewConfiguration()
webView = WKWebView(frame: .zero, configuration: webConfiguration)
webView.uiDelegate = self
// lets us use the two navigations controller functions above
webView.navigationDelegate = self
view = webView
}
override func viewDidLoad() {
super.viewDidLoad()
let myURL = URL(string:"https://stay22.com/embed/sxsw")
let myRequest = URLRequest(url: myURL!)
webView.load(myRequest)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.