[英]Load local HTML/Javascript with WKWebView iOS
I try to load a local HTML game with javascript on WKWebView. 我尝试在WKWebView上使用javascript加载本地HTML游戏。 Although i can see HTML pages styled by the CSS, I can't hear any sound of the game and some game's actions not corresponding.
虽然我可以看到由CSS设计的HTML页面,但我听不到游戏的任何声音和一些游戏的动作不对应。
I notice that if i load exactly the same game via http live server everything seems perfect. 我注意到,如果我通过http直播服务器加载完全相同的游戏,一切似乎都很完美。 So I suppose that something goes wrong with local load.
所以我认为本地负载出了问题。 Maybe this one Apache's issue could be the problem?
也许这一个Apache的问题可能是问题?
Info.plist : Info.plist:
<key>NSAppTransportSecurity</key>
<dict>
<key>NSAllowsArbitraryLoads</key>
<true/>
</dict>
My code (SWIFT 3) : 我的代码(SWIFT 3) :
import UIKit
import WebKit
class WebViewController: AppViewController, WKUIDelegate {
var webView: WKWebView!
override func loadView() {
let webConfiguration = WKWebViewConfiguration()
webView = WKWebView(frame: .zero, configuration: webConfiguration)
webView.uiDelegate = self
view = webView
}
override func viewDidLoad() {
super.viewDidLoad()
if let path = Bundle.main.path(forResource: "index", ofType: "html", inDirectory: "game") {
webView.load(URLRequest(url : URL(fileURLWithPath: path)))
}
}
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.