2017-01-04 40 views
7

Swift 3'ü bir WKWebView'a kullanarak bir çerez ayarlamak için uğraşıyorum. Ben Simülatörü kullanmak ve Safari geliştirin kullanarak incelemek zamanCookie with Swift 3

Ancak
let url = URL(string: "https://s3-us-west-2.amazonaws.com/foo/helloworld.html") 

/* Create cookie and place in cookie storage */ 
let cookieStorage = HTTPCookieStorage.shared 
let cookieHeaderField = ["Set-Cookie": "somecookie=" + cookieString + ";"] 
let cookie = HTTPCookie.cookies(withResponseHeaderFields: cookieHeaderField, for: url!) 
cookieStorage.setCookies(cookie, for: url, mainDocumentURL: nil) 

let urlRequest = URLRequest.init(url: url!) 
theWebView.load(urlRequest) 

, ben hiçbir olduklarını belirtmektedir: Öyle bir başlangıç ​​noktası olarak Swift - How to set cookie in NSMutableURLRequest kullanarak Swift 3 kullanarak herhangi bir örnek bulamadık, bu şimdiye ne var kurabiye seti Ne yaptım ya da hesaba katmadığım şeyler hakkındaki düşünceler?

cevap

1

Swift 3,0

URLRequest'i için çerez ayarlamak için aşağıdaki satırı kullanın:

urlRequest?.setValue("somecookie" + cookieString, forHTTPHeaderField: "Cookie")