4

We need to set a cookie locally to the application that applies to our webview. We referenced this post. All we need is to inject a cookie. When running on the simulator everything works perfect, but when using a device the cookie fails to inject. This is the code we have so far.

let userContentController = WKUserContentController()
let cookieScript = WKUserScript(source: "document.cookie = 'customCookie'; domain = '.example.com'", injectionTime: .AtDocumentStart, forMainFrameOnly: false)

userContentController.addUserScript(cookieScript)
let webViewConfig = WKWebViewConfiguration()
webViewConfig.userContentController = userContentController
self.webView = WKWebView(frame: CGRectZero, configuration: webViewConfig)
Community
  • 1
  • 1
  • What exactly do you mean by "the cookie fails to inject" -- Can you inject other Javascript (like something simpler -- a DOM addition you can see)? – Lou Franco May 17 '16 at 20:18
  • You could try setting the expires date on the cookie. – Onato May 17 '16 at 21:55

0 Answers0