-
-
Save ioniacob/8a5e40851114fae2cac2a59e5a15e287 to your computer and use it in GitHub Desktop.
WKWebView View Controller for Xcode 9.0/Swift 4/iOS11
This file contains hidden or 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 | |
// Honk | |
// | |
// Created by Nick Gressle on 9/23/17. | |
// Copyright © 2017 nick gressle illustrations llc. All rights reserved. | |
// | |
import UIKit | |
import WebKit | |
class ViewController: UIViewController, WKNavigationDelegate { | |
override func viewDidLoad() { | |
super.viewDidLoad() | |
let webView = WKWebView() | |
let htmlPath = Bundle.main.path(forResource: "Honk", ofType: "html") | |
let folderPath = Bundle.main.bundlePath | |
let baseUrl = URL(fileURLWithPath: folderPath, isDirectory: true) | |
do { | |
let htmlString = try NSString(contentsOfFile: htmlPath!, encoding: String.Encoding.utf8.rawValue) | |
webView.loadHTMLString(htmlString as String, baseURL: baseUrl) | |
} catch { | |
// catch error | |
} | |
webView.navigationDelegate = self | |
view = webView | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment