gpt4 book ai didi

swift - 在 Swift 中为 WKWebView 与 WKProcessPool 共享 cookie

转载 作者:行者123 更新时间:2023-11-28 15:19:39 28 4
gpt4 key购买 nike

谁能告诉我如何在 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/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com