0

I have created hello.html file .when I am try to access it,url is returning nil everytime.

  override func viewDidLoad() {
        super.viewDidLoad()
        if let url = Bundle.main.url(forResource: "hello", withExtension: "html"){
            if let htmlData = try? Data(contentsOf:url){
                let baseURL = URL(fileURLWithPath: Bundle.main.bundlePath)
                webView.load(htmlData, mimeType: "text/html", textEncodingName: "UTF-8", baseURL: baseURL)

            }
        }

        // Do any additional setup after loading the view.
    }
Pawan Kumar
  • 508
  • 3
  • 19

1 Answers1

2

enter image description here

  1. drop hello.html in your project
  2. click Copy items if needed
  3. add to targets project
  4. it's ok
Karim
  • 322
  • 4
  • 20
  • But the html file is already in the project. This answer is only useful when adding new files to the project. – rmaddy Feb 07 '18 at 15:40
  • If you html file in sanbox,use `FileManager` get file path,then webview loading,it's ok – Karim Mar 14 '18 at 01:07