作者热门文章
- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
谁能告诉我如何在 Swift 中创建 WKProcessPool?我不熟悉 Objective-C。我必须创建一个 WKProcessPool 以便与所有 WKWebView 共享 cookie。即使在显示另一个具有相同类的 View Controller 时,我也想保留 cookie。我尝试了以下方法,但没有用。
import UIKit
import WebKit
class ViewController: UIViewController, WKNavigationDelegate {
var webView = WKWebView()
override func viewDidLoad() {
super.viewDidLoad()
let processPool = WKProcessPool()
let configuration = WKWebViewConfiguration()
configuration.processPool = WKProcessPool()
webView.navigationDelegate = self
view.addSubview(webView)
}
}
最佳答案
您需要使用 configuration.websiteDataStore 属性而不是 processpool。
对于存储的 cookie,使用 WKWebsiteDataStore.default() 值。对于隐私浏览,请使用 WKWebsiteDataStore.nonPersistent()。
关于swift - 在 Swift 中为 WKWebView 与 WKProcessPool 共享 cookie,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46247464/
感谢下面问题的回答,我想出了如何通过使用 WKProcessPool 在多个 WKWebView 之间使用 Cookie。 Cookie sharing between multiple WKWebV
谁能告诉我如何在 Swift 中创建 WKProcessPool?我不熟悉 Objective-C。我必须创建一个 WKProcessPool 以便与所有 WKWebView 共享 cookie。即使
我是一名优秀的程序员,十分优秀!