0

Tried to make first app in Xcode: took my Web App folder and tried to implement it to XCode project with WebView. But got no success - always blank screen in simulator...

I started new project, created WebView and implement a folder with my Web App through File -> Add files to "MyProject" with option set to copy files and set url to local index.html in view controller. What am I doing wrong?

Project Structure:

-dist
--index.html
--scriptsbundle.js
--img
---myimages.png

-MyProject

-MyProject.xcodeproj

-MyProjectTests

-MyProjectUITests

My ViewController.swift:

import UIKit

class ViewController: UIViewController {


    @IBOutlet var Webview: UIWebView!

    override func viewDidLoad() {
        super.viewDidLoad()

        let url = NSURL(string: Bundle.path(forResource: "index", ofType: "html", inDirectory:"../dist")!)
        let request = NSURLRequest(url: url as! URL)

        Webview.loadRequest(request as URLRequest)


    }

    override func didReceiveMemoryWarning() {
        super.didReceiveMemoryWarning()

    }


}
s.spirit
  • 343
  • 1
  • 7
  • 19
  • 1
    have you tried solutions provided here? http://stackoverflow.com/questions/26647447/load-local-html-into-uiwebview-using-swift – Amod Gokhale Sep 27 '16 at 11:43
  • Yep, thank you. But after some refactor cause of Swift version thought. Now all works, except all images in `img` folder (works only one svg image, implemented in css-style) :( – s.spirit Sep 27 '16 at 12:16

1 Answers1

0

As in the comment, that Amod Gokhale wrote, another article saved my life, but after a bit refactor:

let path = Bundle.main.path(forResource: "index", ofType:"html")
let url = NSURL(string: path!)
let request = NSURLRequest(url: url as! URL)
s.spirit
  • 343
  • 1
  • 7
  • 19