Skip to content

Instantly share code, notes, and snippets.

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
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) {
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() {
let myURL = URL(string:"")
let myRequest = URLRequest(url: myURL!)
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.