Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Swift open local HTML file with parameters

I have a local HTML file that I would like to load in a UIWebView, but would also like to pass a parameter inside. I can load the HTML file

webView.loadRequest(NSURLRequest(URL: NSBundle.mainBundle().URLForResource("apprules", withExtension: "html")!))

I would like to pass the local to the HTML like apprules.html?lang=ja. Is there a way to do this in Swift?

like image 613
Mike Walker Avatar asked Jan 06 '23 00:01

Mike Walker


1 Answers

Swift 3 and up:

let url1 = Bundle.main.url(forResource: "apprules", withExtension: "html")!
let url2 = URL(string: "?lang=ja", relativeTo: url1)!
webView.loadRequest(NSURLRequest(url: url2))

Swift 2 and below:

let url1 = NSBundle.mainBundle().URLForResource("apprules", withExtension: "html")!
let url2 = NSURL(string: "?lang=ja", relativeToURL: url1)!
webView.loadRequest(NSURLRequest(URL: url2))
like image 101
Code Different Avatar answered Jan 14 '23 12:01

Code Different