Join the social network of Tech Nerds, increase skill rank, get work, manage projects...
  • How to Load an iFrame in WKWebView Locally in iOS App

    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 1
    • 0
    • 5.84k
    Comment on it

    WKWebView, introduced in iOS 8 and OS X Yosemite which replaces UIWebView in UIKit and WebView in AppKit UI, it is used to open Safari browser outside the app. It loads web pages faster and more efficiently.



    So, in this blog we will learn how to Load an iFrame in WKWebView locally in an iOS App.

    Let's see the code Example:

    import UIKit
    import WebKit
    let bookData = BookData.sharedInstance
    let quizData = QuizData.sharedInstance
    class ViewController: UIViewController, WKUIDelegate {
        var webView: WKWebView! 
       override func loadView() {
    // implementing web view and giving delegate
          let webViewConfiguration = WKWebViewConfiguration()
            webView = WKWebView(frame: .zero, configuration: webViewConfiguration)
            webView.uiDelegate = self
            view = webView
        override func viewDidLoad() {
            // saving it in a local directory
            let htmlPath = URL(fileURLWithPath:
                    forResource: quizData.questions[quizData.curQuiz][quizData.curQuestion[quizData.curQuiz]].appendix,
                    ofType: "html",
                    inDirectory: "Bookshelf/Books/" + bookData.owned[bookData.bookSelected.ownedId].folder + bookData.owned[bookData.bookSelected.ownedId].version + "/quiz/appendix")!)
            webView.navigationDelegate = self
            webView.loadFileURL(htmlPath, allowingReadAccessTo: htmlPath) 
        override func didReceiveMemoryWarning() {
            // Dispose of any resources that can be recreated.
    extension ViewController: WKNavigationDelegate {
        // When page finishes loading then update ViewController title
        func webView(_ webView: WKWebView, didFinish navigation: WKNavigation!) {
            self.title = webView.title


    Above code will load an iFrame locally In WKWebView. For any question please feel free to write in comments below.

    How to Load an iFrame in WKWebView Locally in iOS App

 0 Comment(s)

Sign In

Sign up using

Forgot Password
Fill out the form below and instructions to reset your password will be emailed to you:
Reset Password
Fill out the form below and reset your password: