【问题标题】:How to save dynamic webpage in cache using UIWebview in Swift 3如何在 Swift 3 中使用 UIWebview 将动态网页保存在缓存中
【发布时间】:2017-06-24 17:43:18
【问题描述】:

我正在开发一个应用程序(使用 UIWebview 的 Swift 3)。我需要将网页加载到 webview 并将一些网页保存到缓存中。如果没有互联网用户将能够看到这些页面。但我对如何将整个网页保存在缓存中感到困惑。最重要的是,即使没有互联网,我们也需要显示页面。

我使用了以下文档:http://nshipster.com/nsurlcache/https://developer.apple.com/reference/foundation/urlcache

let url = NSURL(string: load_url1)
let request = NSURLRequest(url: url as! URL,cachePolicy: NSURLRequest.CachePolicy.returnCacheDataElseLoad, timeoutInterval: 60)
self.webView.loadRequest(request as URLRequest);

以前有没有人实现过这个。请提供一些演示代码,因为这是我第一次尝试缓存

【问题讨论】:

  • 但你的问题太宽泛,无法回答
  • @Anbu.Karthik 我试过这个但是页面没有离线加载
  • 你遇到了什么问题
  • 它只为静态页面加载。在 JSON 数据的帮助下呈现页面时遇到问题

标签: ios caching uiwebview swift3


【解决方案1】:

随便用

let url = URL(string: urlString)
var urlRequest = URLRequest(url: url!)
urlRequest.cachePolicy = .returnCacheDataElseLoad
webView.loadRequest(urlRequest)

【讨论】:

  • 优秀。工作完美。谢谢。
  • 我黑屏了
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2015-03-22
  • 2016-09-28
  • 2013-04-19
  • 1970-01-01
  • 2017-01-09
  • 2016-09-30
相关资源
最近更新 更多