与 WKProcessPool 共享 cookie 用于 Swift 中的 WKWebView [英] Shared cookies with WKProcessPool for WKWebView in Swift

查看:77
本文介绍了与 WKProcessPool 共享 cookie 用于 Swift 中的 WKWebView的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

谁能告诉我如何在 Swift 中创建 WKProcessPool?我不熟悉Objective-C.我必须创建一个 WKProcessPool 以便与所有 WKWebViews 共享 cookie.即使在显示具有相同类的另一个视图控制器时,我也想保留 cookie.我尝试了以下操作,但它不起作用.

Can anyone please tell me how to create a WKProcessPool in Swift? I'm not familiar with Objective-C. I have to create a WKProcessPool in order to have shared cookies with all WKWebViews. I want to keep cookies even when showing another viewcontroller with same class. I tried the following but it's not working.

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.

You need to use configuration.websiteDataStore property instead of processpool.

对于存储的 cookie,使用 WKWebsiteDataStore.default() 值.对于隐私浏览,请使用 WKWebsiteDataStore.nonPersistent().

For the stored cookies use WKWebsiteDataStore.default() value. For the private browsing use WKWebsiteDataStore.nonPersistent().

这篇关于与 WKProcessPool 共享 cookie 用于 Swift 中的 WKWebView的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆