LoginSignup
7
6

More than 5 years have passed since last update.

[Swift] UIWebViewに任意のCookieをセット

Last updated at Posted at 2015-08-30
swift
    var cookieProperties = [String: AnyObject]()
    cookieProperties[NSHTTPCookieName] = "cookiename"
    cookieProperties[NSHTTPCookieValue] = "cookievalue"
    cookieProperties[NSHTTPCookieDomain] = "www.example.com"
    cookieProperties[NSHTTPCookiePath] = "/"
    cookieProperties[NSHTTPCookieVersion] = NSNumber(integer: 0)
    cookieProperties[NSHTTPCookieExpires] = NSDate().dateByAddingTimeInterval(31536000)

    let newCookie = NSHTTPCookie(properties: cookieProperties)
    NSHTTPCookieStorage.sharedHTTPCookieStorage().setCookie(newCookie!)

これで、ドメインwww.example.comに対するcookieがセットされます。

参考(引用):
http://stackoverflow.com/questions/29596206/how-to-get-cookie-from-a-nsurlsession-with-swift

7
6
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
7
6