Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Clear webView cookies (Swift)

How can I clear all cookies for few hosts in my webView? Method from this question not working.

I'm trying to work with vk.com oauth and it does not have user-logout method, so deleting cookis is one of existing ways to make other user possible to log in

Answer is below

like image 234
SwiftStudier Avatar asked Aug 27 '15 17:08

SwiftStudier


1 Answers

I made it by

        let cookieJar = NSHTTPCookieStorage.sharedHTTPCookieStorage()

        for cookie in cookieJar.cookies! {
           // print(cookie.name+"="+cookie.value)
            cookieJar.deleteCookie(cookie)
        }

Swift 4

func removeCookies(){
    let cookieJar = HTTPCookieStorage.shared

    for cookie in cookieJar.cookies! {
        cookieJar.deleteCookie(cookie)
    }
}
like image 114
SwiftStudier Avatar answered Oct 19 '22 06:10

SwiftStudier