我有一个本地 HTML 文件,我想将其加载到 UIWebView
中,但也想在其中传递一个参数。我可以加载 HTML 文件
webView.loadRequest(NSURLRequest(URL: NSBundle.mainBundle().URLForResource("apprules", withExtension: "html")!))
我想将本地传递给 apprules.html?lang=ja
之类的 HTML。有没有办法在 Swift 中做到这一点?
最佳答案
Swift 3 及更高版本:
let url1 = Bundle.main.url(forResource: "apprules", withExtension: "html")!
let url2 = URL(string: "?lang=ja", relativeTo: url1)!
webView.loadRequest(NSURLRequest(url: url2))
Swift 2 及以下版本:
let url1 = NSBundle.mainBundle().URLForResource("apprules", withExtension: "html")!
let url2 = NSURL(string: "?lang=ja", relativeToURL: url1)!
webView.loadRequest(NSURLRequest(URL: url2))
关于html - Swift 打开带参数的本地 HTML 文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37466554/