How to get offline mode? open .html | iOS

I buy RocketWeb from CodeCanyon now I want to open an offline HTML page in my app.

It’s possible to use the offline page but it does do not work like host web project. Because your mobile device is not a server. For basic or sample pages it’s will be fine.

First of all pastes your offline pages on the Resources folder. For example, I want to open index.html here.

Then on the configure page set your file name with file:///. So in my case name will be file:///index.html.

Then set this line of code if not exist on your version. And set your file name with the file type. In my case file name index and file type html

private func loadWebView(loadUrl: String){
       
if (loadUrl.contains("file:///")){
           
let path = Bundle.main.path(forResource: "index", ofType: "HTML")
           
var html = ""
           
do {
               
try html = String(contentsOfFile: path!, encoding: .utf8)
            }
catch {
               printLog(tag: TAG, message: "Offline path is invalid.")
            }
           
self.viewWeb.loadHTMLString(html, baseURL: URL(string: Constants.BASE_URL)!)
        }
       
else if let url = URL(string: loadUrl) {
           
self.viewWeb.load(URLRequest(url: URL))
        }
    }

2 thoughts on “How to get offline mode? open .html | iOS

Leave a Reply