WKWebView Cache manifest not working IOS8

前端 未结 2 1470
傲寒
傲寒 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: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)
    

提交回复
热议问题