WKWebView缓存清单无法使用IOS8 [英] WKWebView Cache manifest not working IOS8

查看:65
本文介绍了WKWebView缓存清单无法使用IOS8的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

缓存清单可以正常运行,并且事件可以在IOS 8的safari中触发.在WKWebView中根本无法正常工作的人解决了这个问题吗?

导入UIKit

导入WebKit

class ViewController: UIViewController {
@IBOutlet var containterView : UIView! = nil
var webView : WKWebView?
override func loadView(){
    super.loadView()
    self.webView = WKWebView()
    self.view = self.webView!
}
override func viewDidLoad() {
    super.viewDidLoad()
    var url = NSURL(string:"http://html5demos.com/offlineapp")
    var req = NSURLRequest(URL:url)
    self.webView!.loadRequest(req)
}

override func didReceiveMemoryWarning() {
    super.didReceiveMemoryWarning()
}

}

如果我使用html5test.com,应用程序缓存将返回受支持的位置

从WKWebView加载

window.applicationCache也不返回未定义

console.log("Initializing Page");       
if (window.applicationCache == undefined){
    console.log("Application cache not suported!");
    updateSplash();
}
console.log(window.applicationCache); returns: DOMApplicationCache

if (typeof window.applicationCache.update === 'function'){
        console.log("Application has method update");
        console.log(window.applicationCache.update); //shows swapCache() and update() methods
        window.applicationCache.update();   
    }

window.applicationCAche.update()引发错误:InvalidStateError:DOM异常11:试图使用一个不可用或不再可用的对象.

解决方案

仅作记录,该问题似乎已被问过并链接到 https://bugreport.apple.com 使其可用.

Cache manifest works fine and events fired in safari in IOS 8. Not working at all in WKWebView anyone else solve this issue?

import UIKit

import WebKit

class ViewController: UIViewController {
@IBOutlet var containterView : UIView! = nil
var webView : WKWebView?
override func loadView(){
    super.loadView()
    self.webView = WKWebView()
    self.view = self.webView!
}
override func viewDidLoad() {
    super.viewDidLoad()
    var url = NSURL(string:"http://html5demos.com/offlineapp")
    var req = NSURLRequest(URL:url)
    self.webView!.loadRequest(req)
}

override func didReceiveMemoryWarning() {
    super.didReceiveMemoryWarning()
}

}

The application cache comes back as supported if I were to use html5test.com

EDIT:

window.applicationCache does not return undefined either when loaded from WKWebView

console.log("Initializing Page");       
if (window.applicationCache == undefined){
    console.log("Application cache not suported!");
    updateSplash();
}
console.log(window.applicationCache); returns: DOMApplicationCache

EDIT 2:

if (typeof window.applicationCache.update === 'function'){
        console.log("Application has method update");
        console.log(window.applicationCache.update); //shows swapCache() and update() methods
        window.applicationCache.update();   
    }

window.applicationCAche.update() throws Error: InvalidStateError: DOM Exception 11: An attempt was made to use an object that is not, or is no longer, usable.

解决方案

Just for the record, this question appears to have been asked on and linked from the Apple Developer Forums. The official response from Apple is that the HTML5 Application Cache functionality is not available in WKWebView:

The offline application cache is not enabled in WKWebView. Feel free to request that it be made available via https://bugreport.apple.com.

这篇关于WKWebView缓存清单无法使用IOS8的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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