WKWebView showing blank on device, working on simulator

被刻印的时光 ゝ 提交于 2019-11-30 20:13:40

问题


One of the modules of my app is a web site. That web site contains primarily an SVG drawing, with custom shaped buttons (using Raphael.js library) to access other drawings (other html page with svg drawings).

If the device is on iOS 7, I use a UIWebView and everything works fine.

For iOS 8 devices, I use a WKWebView. I had some issues, some of them resolved by this post. I can see my web site on those simulators (iPhone 5 / iOS 8.0 (12A365) & iPhone 5s / iOS 8.0), but I can't see it on my iPod Touch (5th gen, running iOS 8.0.2). It shows a blank screen.

I don't know what to look for. Any idea?


EDIT

After following @Dan Fabulich's answer (here), I now get a forever-loading webview, that never finishes loading up. His answer tells us that there is a bug with WKWebView when loading html from a string. His answer is to copy the html content into a new subfolder and then call loadRequest from that URL.

Unfortunately, I'm still stuck with a non-working webview. Any clue? What would be a reason for a webview to never finish loading up content?


回答1:


i had some problem but i solved problem with configuration options. here is my my code.

    var a = dic["adi"]?.asString()
    var path = NSBundle.mainBundle().pathForResource(a, ofType: "htm" )
    var url = NSURL(fileURLWithPath:path!)
    var request = NSURLRequest(URL:url!)

    var theConfiguration = WKWebViewConfiguration()

    theWebView = WKWebView(frame:self.view.frame, configuration: theConfiguration)

    var error:NSError?
    let text2 = String(contentsOfFile: path!, encoding:NSUTF8StringEncoding, error: &error)

    if let theError = error
    {
        print("\(theError.localizedDescription)")
    }

    theWebView!.loadHTMLString(text2!, baseURL: nil)
    self.view.addSubview(theWebView!)

hope this helps.



来源:https://stackoverflow.com/questions/26455432/wkwebview-showing-blank-on-device-working-on-simulator

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!