I'm trying to test a url within a webview in swift in Xcode 6.1 that requires cookies, and I'm having issues with accepting cookies by default.
Previously, in Objective-C, I had the following working:
[NSHTTPCookieStorage sharedHTTPCookieStorage].cookieAcceptPolicy = NSHTTPCookieAcceptPolicyAlways;
NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:self.URL];
[request setHTTPShouldHandleCookies:YES];
[self.webView loadRequest:request];
Here is my test with Swift that throws an error about the cookie policy:
@IBOutlet var webView: UIWebView!
override func viewDidLoad() {
super.viewDidLoad()
let url = NSURL(string: "http://testlink.com/")
let request = NSMutableURLRequest(URL: url!)
request.HTTPShouldHandleCookies = true
webView.loadRequest(request)
}
A note, the url that I end up at is not the one initially loaded. It has to be navigated to through a login.
Any help porting this over would be much appreciated.