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
  • 8,323
  • 2
  • 36
  • 39
Victor Balbo
  • 33
  • 1
  • 7

1 Answers1

6

The olde missing semicolon strikes again!

let request = NSMutableURLRequest(url: myUrl! as URL)
request.addValue("CookieKey=value;", forHTTPHeaderField: "Cookie")
// ------------------------------
Coder-256
  • 4,689
  • 1
  • 22
  • 49