缓存清单工作正常,并且在 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,应用程序缓存将恢复受支持
EDIT:
从 WKWebView 加载时,window.applicationCache 也不会返回未定义
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() 抛出错误:InvalidStateError:DOM 异常 11:尝试使用不可用或不再可用的对象。
仅供记录,这个问题似乎是在苹果开发者论坛 https://devforums.apple.com/message/1060452。苹果官方的回应是,WKWebView 中不提供 HTML5 Application Cache 功能:
WKWebView 中未启用离线应用程序缓存。请随时请求通过以下方式提供https://bugreport.apple.com https://bugreport.apple.com.
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)