WKWebView Cache manifest not working IOS8

前端 未结 2 1463
傲寒
傲寒 2021-02-09 16:58

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

相关标签:
2条回答
  • 2021-02-09 17:17

    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.

    0 讨论(0)
  • 2021-02-09 17:38

    I think you are trying to solve the same problem as I do. This is what I do.

    1. Save the start page of your web app into one HTML file(index.html), embedding everything (CSS, JS, images as base 64, icon fonts). And add that file into your Xcode project.
    2. Start the app by reading the content of the HTML file and load it in your WKWebView. You can set the base as the same url you are supposed to start with. This way, it'll be as if the web app is opened on your web site.

    The benefit is that your app will always start even when the user's network isn't good. Here's the SWIFT code that I use, courtesy of Matt Neuberg (https://books.google.com/books?id=wLaVBQAAQBAJ&pg=PT669&lpg=PT669&dq=addConstraints+wkwebview&source=bl&ots=7trE7MR1zR&sig=VT6GDBGbDw9dh89wDb5Uajd4gUY&hl=en&sa=X&ei=cyyeVNH4MM3ToATukoDgAQ&ved=0CDkQ6AEwBA#v=onepage&q=addConstraints%20wkwebview&f=false). If you want the full source code, please let me know and I'll post it on Github.

        let templatepath = NSBundle.mainBundle().pathForResource("index", ofType: "html")!
        let base = NSURL(string:"http://m.ftchinese.com/iphone-2014.html#iOSShare")
        var s = NSString(contentsOfFile:templatepath, encoding:NSUTF8StringEncoding, error:nil)!
        self.webView!.loadHTMLString(s, baseURL:base)
    
    0 讨论(0)
提交回复
热议问题