LoginSignup
25
22

More than 5 years have passed since last update.

UIWebViewにCookieをセット・削除

Last updated at Posted at 2014-10-31

セット

// 1
let storage = NSHTTPCookieStorage.sharedHTTPCookieStorage()
let cookies = NSHTTPCookieStorage.cookiesForURL(storage)(NSURL(string: host_url)!)
NSHTTPCookieStorage.sharedHTTPCookieStorage().setCookies(cookies!, forURL: host_url)

// 2
NSURL(string: host_url)!, mainDocumentURL: NSURL(string: host_url)!)
        for cookie : NSHTTPCookie in NSHTTPCookieStorage.sharedHTTPCookieStorage().cookiesForURL(NSURL(string: host_url)!) as [NSHTTPCookie] {
            NSHTTPCookieStorage.sharedHTTPCookieStorage().setCookie(cookie)
        }

削除

let storage = NSHTTPCookieStorage.sharedHTTPCookieStorage()
for cookie : NSHTTPCookie in NSHTTPCookieStorage.sharedHTTPCookieStorage().cookiesForURL(NSURL(string: url.host)!) as [NSHTTPCookie] {
    storage.deleteCookie(cookie)
}
25
22
2

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
25
22