<small id='IrIEq'></small><noframes id='IrIEq'>

<legend id='IrIEq'><style id='IrIEq'><dir id='IrIEq'><q id='IrIEq'></q></dir></style></legend>
      1. <tfoot id='IrIEq'></tfoot>
        <i id='IrIEq'><tr id='IrIEq'><dt id='IrIEq'><q id='IrIEq'><span id='IrIEq'><b id='IrIEq'><form id='IrIEq'><ins id='IrIEq'></ins><ul id='IrIEq'></ul><sub id='IrIEq'></sub></form><legend id='IrIEq'></legend><bdo id='IrIEq'><pre id='IrIEq'><center id='IrIEq'></center></pre></bdo></b><th id='IrIEq'></th></span></q></dt></tr></i><div id='IrIEq'><tfoot id='IrIEq'></tfoot><dl id='IrIEq'><fieldset id='IrIEq'></fieldset></dl></div>

        • <bdo id='IrIEq'></bdo><ul id='IrIEq'></ul>
      2. 两个单独的 cookie 存储(UIWebView 或 WKWebView)

        时间:2023-11-09

        <small id='7cI7C'></small><noframes id='7cI7C'>

                <tbody id='7cI7C'></tbody>
              <tfoot id='7cI7C'></tfoot>
            1. <legend id='7cI7C'><style id='7cI7C'><dir id='7cI7C'><q id='7cI7C'></q></dir></style></legend>
                <bdo id='7cI7C'></bdo><ul id='7cI7C'></ul>
                <i id='7cI7C'><tr id='7cI7C'><dt id='7cI7C'><q id='7cI7C'><span id='7cI7C'><b id='7cI7C'><form id='7cI7C'><ins id='7cI7C'></ins><ul id='7cI7C'></ul><sub id='7cI7C'></sub></form><legend id='7cI7C'></legend><bdo id='7cI7C'><pre id='7cI7C'><center id='7cI7C'></center></pre></bdo></b><th id='7cI7C'></th></span></q></dt></tr></i><div id='7cI7C'><tfoot id='7cI7C'></tfoot><dl id='7cI7C'><fieldset id='7cI7C'></fieldset></dl></div>

                  本文介绍了两个单独的 cookie 存储(UIWebView 或 WKWebView)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  我想在不同的 webView 中登录同一站点的多个帐户.例如,我的 Tab Bar Controller 包含三个 view controllers 并且每个 view controllers 包含 webView.例如,我在每个类中为 webView 嵌入了 stackoverflow url.用户如何使用这三个 webView 同时登录不同的帐户?我已经尝试过了,但我一次只能登录一个用户.我发现我需要为每个 UIWebView 创建单独的 cookie,但大多数答案都在 Objective-c 中,而不是我想要的正确答案.例如(

                  解决方案

                  您可以通过使用 WKWebSiteDataStore 的不同实例来使用 WKWebView 来做到这一点:

                  让配置1 = WKWebViewConfiguration()configuration1.websiteDataStore = WKWebsiteDataStore.nonPersistent()self.webView1 = WKWebView(frame: CGRect.zero, configuration: configuration1)self.view.addSubview(self.webView1)让配置2 = WKWebViewConfiguration()configuration2.websiteDataStore = WKWebsiteDataStore.nonPersistent()self.webView2 = WKWebView(frame: CGRect.zero, configuration: configuration2)

                  不幸的是,应用重启后你会丢失 webView 数据(如 cookie、缓存等),因为非持久性 WKWebsiteDataStore 无法保存到磁盘(您会注意到 WKWebsiteDataStore 实现了 NSCoding,但它不适用于非持久性存储).

                  I want to login many accounts of same site in different webView. For example i have Tab Bar Controller that contains three view controllers and each view controllers contain webView. And for example i embed stackoverflow url for webView in every class. How user can login to different accounts at the same time using these three webView? I've tried this but i can just login one user at a time. I have found that i need to create separate cookie for every UIWebView, but mostly answers are in objective-c and not the proper answer i want. For example (First Second Third) Can any one please tell me how i can do it?

                  class FirstViewController: UIViewController , UIWebViewDelegate{
                  
                      @IBOutlet weak var webView: UIWebView!
                      @IBOutlet weak var activityIndicator: UIActivityIndicatorView!
                  
                      override func viewDidLoad() {
                          webView.delegate = self
                          let requestURL = NSURL(string: "http://stackoverflow.com")
                          let request = NSURLRequest(URL: requestURL!)
                          activityIndicator.hidesWhenStopped = true
                          activityIndicator.startAnimating()
                          webView.loadRequest(request)
                  
                      }
                         func webViewDidFinishLoad(webView: UIWebView) {
                          activityIndicator.stopAnimating()
                      }
                  
                  }
                  
                  class SecondViewController: UIViewController, UIWebViewDelegate{
                  
                      @IBOutlet weak var webView: UIWebView!
                      @IBOutlet weak var activityIndicator: UIActivityIndicatorView!
                  
                      override func viewDidLoad() {
                          webView.delegate = self
                          let requestURL = NSURL(string: "http://stackoverflow.com")
                          let request = NSURLRequest(URL: requestURL!)
                          activityIndicator.hidesWhenStopped = true
                          activityIndicator.startAnimating()
                          webView.loadRequest(request)
                  
                      }
                          func webViewDidFinishLoad(webView: UIWebView) {
                          activityIndicator.stopAnimating()
                      }
                  
                  
                  }
                  

                  Thanks

                  解决方案

                  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).

                  这篇关于两个单独的 cookie 存储(UIWebView 或 WKWebView)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                  上一篇:iPhone UIWebView - 可以在输入文本字段上关闭自动完成功能吗? 下一篇:使用带有 UIWebView 和 POST 请求的自定义 NSURLProtocol

                  相关文章

                  <tfoot id='PyLms'></tfoot>

                  • <bdo id='PyLms'></bdo><ul id='PyLms'></ul>
                1. <small id='PyLms'></small><noframes id='PyLms'>

                      <i id='PyLms'><tr id='PyLms'><dt id='PyLms'><q id='PyLms'><span id='PyLms'><b id='PyLms'><form id='PyLms'><ins id='PyLms'></ins><ul id='PyLms'></ul><sub id='PyLms'></sub></form><legend id='PyLms'></legend><bdo id='PyLms'><pre id='PyLms'><center id='PyLms'></center></pre></bdo></b><th id='PyLms'></th></span></q></dt></tr></i><div id='PyLms'><tfoot id='PyLms'></tfoot><dl id='PyLms'><fieldset id='PyLms'></fieldset></dl></div>

                      <legend id='PyLms'><style id='PyLms'><dir id='PyLms'><q id='PyLms'></q></dir></style></legend>