7
6

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

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

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?