【问题标题】:iOS Webkit not working on device, but works on simulator at swiftiOS Webkit 无法在设备上运行,但可以在模拟器上快速运行
【发布时间】:2014-09-22 21:31:59
【问题描述】:

我在程序中使用 htm 文件进行一些工作。在模拟器中我定义了这样的本地文件;

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

    var theWebView:WKWebView = WKWebView(frame:self.view.frame)
    theWebView.loadRequest(request)
    self.view.addSubview(theWebView)

但是当我将此应用程序发送到设备(iPhone 5s)时

出现错误: file:///private/var/mobile/Containers/Bundle/Application/2E9F7BCA-D57E-4C47-8BBC-6CBF2FF2B2E1/Receteler.app/Akciger_odemi_Akut_Kalp_Yetmezligi.htm 无法为“/”创建沙盒扩展

这是我在项目中的 htm 文件夹。我从桌面添加了它们“将文件添加到项目”

你能帮我解释一下为什么我会出错吗?

导入文件错误的原因或 关于捆绑? 我不太了解objective-c,所以如果你用swift给我建议,我会很高兴的。

谢谢

【问题讨论】:

    标签: ios swift webkit bundle


    【解决方案1】:

    您缺少 WKWebView 配置。请在加载您的 html 文件之前添加以下行以解决问题。

    var theConfiguration = WKWebViewConfiguration()

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2011-03-31
      • 2017-10-28
      • 1970-01-01
      • 2014-12-24
      • 2018-10-16
      • 1970-01-01
      • 1970-01-01
      • 2012-10-27
      相关资源
      最近更新 更多