如何使用EVURLCache在PreCache中加载UIWebView

我尝试创build一个iOS应用程序,有一个UIWebview,我想加载它的网站。 我尝试使用EVURLCache进行caching。 但是它不会从我的项目中的PreCache文件夹加载。

该应用程序运行良好。 但是,当我尝试再次运行它只显示我的空白屏幕。 我认为应用程序尝试从caching中加载页面,但应用程序无法find它的caching。

我使用https://github.com/evermeer/EVURLCache进行caching。 我通过豆荚安装

MainVC

import UIKit class MainVC: UIViewController, UIWebViewDelegate { @IBOutlet weak var webView: UIWebView! override func viewDidLoad() { super.viewDidLoad() webView.delegate = self let url = URL(string: BASE_URL) let request = URLRequest(url: url!) webView.loadRequest(request) } func webViewDidStartLoad(_ webView: UIWebView) { print("*****************") print(" webViewDidStartLoad(") print("*****************") } func webViewDidFinishLoad(_ webView: UIWebView) { print("*****************") print("webViewDidFinishLoad") print("*****************") } } 

AppDelegate中

 func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool { // Override point for customization after application launch. EVURLCache.LOGGING = true // We want to see all caching actions EVURLCache.MAX_FILE_SIZE = 26 // We want more than the default: 2^26 = 64MB EVURLCache.MAX_CACHE_SIZE = 30 // We want more than the default: 2^30 = 1GB EVURLCache.activate() return true } 

我find了Cache文件夹

 04/10/2017 18:01:41:952 FedNet)[1696:.] EVURLCache.swift(245) storeCachedResponse(_:for:): CACHE save file to Cache : /Users/apple/Library/Developer/CoreSimulator/Devices/BF935382-BD49-4F37-85A1-C3FA0E1B094B/data/Containers/Data/Application/AF33E59E-1BB4-46CC-9236-BEB42F53D606/Documents/Cache/www.fednetbank.com/corp/l001/consumer/theme/login/img/banner.jpg 

在这里输入图像说明

当我运行与PreCache文件夹的应用程序,它给了我一个空白的屏幕….

这可能是由redirect造成的。 redirect不被caching。 我试图用协议来解决这个问题,但是我已经注意到它有时会失败。 你可以尝试从EVURLCache中删除以下行,然后再试一次?

 URLProtocol.registerClass(EVURLProtocol.self)