-
-
Save trevorstarick/f5586eef9d09f0116ca6a8713f529708 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// | |
// 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