Separate cookie storage for two (UIWebView or WKWebView)

前端 未结 1 1654
一生所求
一生所求 2020-12-17 22:32

I want to login many accounts of same site in different webView. For example i have Tab Bar Controller that contains three view controllers

相关标签:
1条回答
  • 2020-12-17 23:10

    You can do this with WKWebView by using different instances of WKWebSiteDataStore:

    let configuration1 = WKWebViewConfiguration()
    configuration1.websiteDataStore = WKWebsiteDataStore.nonPersistent()
    self.webView1 = WKWebView(frame: CGRect.zero, configuration: configuration1)
    self.view.addSubview(self.webView1)
    
    let configuration2 = WKWebViewConfiguration()
    configuration2.websiteDataStore = WKWebsiteDataStore.nonPersistent()
    self.webView2 = WKWebView(frame: CGRect.zero, configuration: configuration2)
    

    Unfortunately, you will loose webView data (such as cookies, cache, etc) after app restart, because non-persistent WKWebsiteDataStore can't be saved to disk (you could notice that WKWebsiteDataStore implements NSCoding, but it doesn't work for non-persistent stores).

    0 讨论(0)
提交回复
热议问题