Post

Replies

Boosts

Views

Activity

Reply to WKWebview datastore not returning all cookies that were set
After a week struggling, I found a way to make it work. Posting here in case anyone need. #1 Have an instance of processPool and wesiteDataStore.nonpersistent() (make them a global variables if you want to get the Cookies outside of webview didFinish navigation of the same wkWebview) #2 Create an instance of wkWebviewconfigure with these two: var wkWebviewconfigure: WKWebViewConfiguration = WKWebViewConfiguration() wkWebviewconfigure.processPool = myProcessPool wkWebviewconfigure.websiteDatastore = myWebsiteDatastore // <--- have to be nonpersistent type #3 Generate webview from code with this wkWebviewconfigure, assigning wkWebviewconfigure to your wkWebview.configuration from .xib and storyboard will not work
Aug ’20
Reply to WKWebview datastore not returning all cookies that were set
I already implement with singleton WKProcessPool and pass here when initialize this WKWebviewViewController. Here is a sample logic I used to check the cookies from an website url after it finishes the navigation, cookies does not there import UIKit import WebKit class WKWebviewViewController: UIViewController, WKUIDelegate, WKNavigationDelegate {   var urlToLoad: String = "&lt;any website url, I even try with apple.com&gt;"   var cookiesTxt: String! var processPool: WKProcessPool!   var wkWebviewconfigure: WKWebViewConfiguration = WKWebViewConfiguration()   var webView: WKWebView!   override func viewDidLoad() {     super.viewDidLoad()     // webView programatically     let bounds = self.view.bounds     let frame = CGRect(x: bounds.origin.x, y: bounds.origin.y + 100, width: bounds.width, height: bounds.height)    wkWebviewconfigure.processPool = processPool     self.webView = WKWebView(frame: frame, configuration: wkWebviewconfigure)     self.view.addSubview(self.webView)     webView.navigationDelegate = self     webView.uiDelegate = self     if let url = URL(string: urlToLoad) {       let request = URLRequest(url: url)       DispatchQueue.main.async {         self.webView.load(request)       }     }   }    public func webView(_ webView: WKWebView, didFinish navigation: WKNavigation!) {     let httpCookieStore = webView.configuration.websiteDataStore.httpCookieStore     httpCookieStore.getAllCookies { (cookies) in       print(cookies) // <--- not getting all the cookies most of time here, but sometime it works     }   } }
Aug ’20