Storage
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