我希望webview能够保存缓存,以便以后用于快速Web加载,这个用swift 3编写的webview代码 你能帮帮我吗
import UIKit
class FirstViewController: UIViewController {
@IBOutlet var webfirst: UIWebView!
override func viewDidLoad() {
super.viewDidLoad()
let urlfirst = URL(string: "https://google.com")
webfirst?.loadRequest(URLRequest(url:urlfirst!))
}
override var prefersStatusBarHidden: Bool {
return true
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
}
}
答案 0 :(得分:0)
只需将cachePolicy设置为.returnCacheDataElseLoad
let urlfirst = URL(string: "https://google.com")
var urlRequest = URLRequest(url:urlfirst!)
urlRequest.cachePolicy = .returnCacheDataElseLoad
webfirst?.loadRequest(urlRequest)