WKWebView 在设备上显示空白,在模拟器上工作 [英] WKWebView showing blank on device, working on simulator

查看:23
本文介绍了WKWebView 在设备上显示空白,在模拟器上工作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的应用程序的模块之一是网站.该网站主要包含一个 SVG 绘图,带有自定义形状的按钮(使用 Raphael.js 库)来访问其他绘图(其他带有 svg 绘图的 html 页面).

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).

如果设备在 iOS 7 上,我使用 UIWebView,一切正常.

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

对于 iOS 8 设备,我使用 WKWebView.我遇到了一些问题,其中一些已通过这篇文章解决.我可以在这些模拟器(iPhone 5/iOS 8.0 (12A365) 和 iPhone 5s/iOS 8.0)上看到我的网站,但在我的 iPod Touch(第 5 代,运行 iOS 8.0.2)上看不到它.它显示一个空白屏幕.

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?

编辑

在遵循@Dan Fabulich 的回答(此处)之后,我现在得到了一个永远加载的 web 视图,它永远不会完成加载向上.他的回答告诉我们,从字符串加载 html 时 WKWebView 存在错误.他的回答是将 html 内容复制到一个新的子文件夹中,然后从该 URL 调用 loadRequest.

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.

不幸的是,我仍然无法正常工作.有什么线索吗?webview 永远无法完成加载内容的原因是什么?

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?

推荐答案

我遇到了一些问题,但我解决了配置选项的问题.这是我的代码.

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!)

希望这会有所帮助.

这篇关于WKWebView 在设备上显示空白,在模拟器上工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆