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

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

问题描述

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



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



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



我不知道该找什么。有什么想法?






编辑



<在听完@Dan Fabulich的回答(这里)之后,我现在得到一个永远加载的webview,永远不会完成加载。他的回答告诉我们,当从字符串加载html时,WKWebView存在一个错误。他的回答是将html内容复制到一个新的子文件夹中,然后从该URL调用 loadRequest



不幸的是,我仍然坚持使用非工作webview。任何线索? webview永远不会完成加载内容的原因是什么?

解决方案

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

  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)

如果让theError =错误
{
print(\\ \\(theError.localizedDescription))
}

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

希望这有帮助。


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?

解决方案

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.

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

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