Search code examples
swiftxcodecookiessession-cookieswkwebview

Cookies Sharing between wkwebviews


I have an Xcode project in Swift with multiple wkwebviews and a tabbbar so that the user can switch between home, account, shoppingcart, etc.

But the problem is that when the user puts something in the shoppingcart under the home webview and moves to shoppingcart webview the items are not visible.

here is video which shows the problem: https://www.youtube.com/watch?v=qU3Mu1G7MY0&feature=youtu.be

Could you provide a example code how I can store an cookie under viewHome and then load that cookie in an different wkwebview under viewShopping

Please modify the Code in the GitHub repo I am new to swift so an explanation won't help only a finished code

https://github.com/TsGamesUE/multiplewkwebviews/


Solution

  • Try the following code in your loadView() for both of your ViewController classes:

    webConfiguration.processPool = viewHome.processPool

    override func loadView() {
            let webConfiguration = WKWebViewConfiguration()
            webConfiguration.processPool = viewHome.processPool
            webViewHome = WKWebView(frame: .zero, configuration: webConfiguration)
    

    Additional:For standard, please Use the camel case in the Class name convention (viewHome -> ViewHome).