Storage

Older implementations of UIWebView allowed localStorage by default, but it has been deprecated. If any of your customers are using it, they should switch to WKWebView.

Enable localStorage & sessionStorage

let webView = WKWebView(frame: .zero, configuration: WKWebViewConfiguration())
webView.configuration.websiteDataStore = WKWebsiteDataStore.default()

Enable JavaScript

Ensure JavaScript is enabled because localStorage requires it:

webView.configuration.defaultWebpagePreferences.allowsContentJavaScript = true

Prevent WebView Data Loss (iOS 11+)

By default, WKWebView might clear storage (including localStorage) when the app is backgrounded. To avoid this, set default() storage:

webView.configuration.websiteDataStore = WKWebsiteDataStore.default()

Last updated