1

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.

hisnameisjimmy
  • 1,508
  • 2
  • 17
  • 24
  • Hey. Did you ever figure this out? I'm working on an app with the same scenario and I still can't figure this out. – Lavvo Apr 23 '15 at 18:21
  • maybe this post could help http://stackoverflow.com/questions/26005641/are-cookies-in-uiwebview-accepted – Ferico Samuel Oct 05 '16 at 02:41

0 Answers0