how to load UIWebView in PreCache using EVURLCache

若如初见. 提交于 2019-12-25 16:42:02

问题


I am try to create an iOS app, that have a UIWebview and I want to load the website inside it. I try to use EVURLCache for caching. But it doesn't load from the PreCache folder inside my project.

The app run first time fine. But when I try to run again it shows me blank screen only. I think the app try to load the page from the cache, but the app can't find its caches..

I use https://github.com/evermeer/EVURLCache for caching. And I install via pods

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
    }

And I found the Cache folder

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

And when I run the app with the PreCache folder it gives me a blank screen....


回答1:


This could be caused by a redirect. Redirects are not cached. I tried to solve that with a protocol but I already noticed that it sometimes fails. Could you try removing the following line from EVURLCache and then try again?

URLProtocol.registerClass(EVURLProtocol.self)


来源:https://stackoverflow.com/questions/43325780/how-to-load-uiwebview-in-precache-using-evurlcache

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!