Abduhafiz
Abduhafiz

Reputation: 3404

Load html file to WebView from local custom folder in swift 3

I want to load html file to WebView from local custom folder - ProjectNameFolder/test/index.html.

Trying this code, but doesn't work.

mWebView.loadRequest(URLRequest(url: URL(fileURLWithPath: Bundle.main.path(forResource: "test/index", ofType: "html")!) as URL))

EDITED

When I do without folder name, works perfectly.

mWebView.loadRequest(URLRequest(url: URL(fileURLWithPath: Bundle.main.path(forResource: "index", ofType: "html")!) as URL))

P.S. I'm new in Swift.

Upvotes: 3

Views: 4809

Answers (1)

Abduhafiz
Abduhafiz

Reputation: 3404

I found solution for my problem.

Drag and drop test folder into project folder.

enter image description here

enter image description here

Here is code

override func viewDidLoad() {
    super.viewDidLoad()     
    mWebView.loadRequest(URLRequest(url: URL(fileURLWithPath: Bundle.main.path(forResource: "test/index", ofType: "html")!)))
}

Upvotes: 4

Related Questions