Randy
Randy

Reputation: 4525

How to prevent WKWebView from being emptied after app sent to background

I am developing an app that uses WKWebView to render web content. Everything works fine so far except one thing: if I load a page on my WKWebView then send the app to the background for a while (I'd say around ten minutes) and reopen the app, my WKWebView is empty.

I guess it is automatically emptied to prevent memory waste, but then what do Safari or Chrome do in order to keep the web page content in memory?

Upvotes: 2

Views: 1529

Answers (1)

Duncan C
Duncan C

Reputation: 131398

Short answer: You can't.

My guess is that your app is actually getting terminated while it is suspended, and you are getting re-launched. You can't prevent that either.

If the system needs memory it will send your app a low memory app delegate message and notification. The WKWebView may subscribe to that notification and clear the page if it gets a low memory notification.

Upvotes: 1

Related Questions