2

I'm trying to set a WKWebView in my iOS app and set a cookie with the authentication info but I couldn't find a way to set cookies in Swift. I saw some questions but all the answers were in Objective-C. I tried to do some ideas for a Swift solution but I am also new in iOS development. I tried to do something like:

let request = NSMutableURLRequest(url: myUrl! as URL)
request.addValue("CookieKey=value", forHTTPHeaderField: "Cookie")

but it didn't work. When I load the page the cookies have not been set. Can any one help me?

yedpodtrzitko
  • 9,035
  • 2
  • 40
  • 42
Victor Balbo
  • 63
  • 1
  • 9

1 Answers1

6

The olde missing semicolon strikes again!

let request = NSMutableURLRequest(url: myUrl! as URL)
request.addValue("CookieKey=value;", forHTTPHeaderField: "Cookie")
// ------------------------------
Coder-256
  • 5,212
  • 2
  • 23
  • 51