3

In my app users can open a website. The website is heavy with content (20MB average). A lot of my users don't have access to the internet at all times, so it's essential that we save any content they open (at the same time they view it). And then the next time they open it, it's completely loaded from the disk.

Here's what I'm thinking:

  1. Use UIWebView and cache everything .. that's working but UIWebview is depreciated.
  2. Use WKWebView, but I cannot cache everything :( Im not even sure I can intercept all the requests and responses.
  3. Use a proxy server inside the app and save all data as it's being loaded from the remote server, I have no idea how to start this.

Basically, I want something similar to https://github.com/evermeer/EVURLCache but for WKWebView

The question: Which approach do you recommend? And how can I get around the downsides mentioned ?

Ahmed
  • 47
  • 5

1 Answers1

0

With WKWebView you can use URLRequests to load your website data and cache it. The URLRequest can be configured in their caching policy during initialization.

init(url URL: URL, 
cachePolicy: NSURLRequest.CachePolicy, 
timeoutInterval: TimeInterval)

You could try to go forward with returnCacheDataElseLoad. However, this probably would not cover your particular case even if the cache is used primarily. Have a look at this answer regarding application cache and WKWebView.

ff10
  • 3,046
  • 1
  • 32
  • 55
  • Thank you @ff10 I tried this approach. It does cache the images and resources, but for some reason, the audio files are not cached. – Ahmed Aug 22 '18 at 15:04