Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Alamofire clear all cookies

I need the user to be able to log out. When they log in now, a cookie gets saved automatically, that works fine. But I want to clear all cookies.

NSURLCache.sharedURLCache().removeAllCachedResponses()

This does not work

like image 656
alvarlagerlof Avatar asked Oct 12 '16 15:10

alvarlagerlof


1 Answers

You can remove all the cookies specifically stored for an URL like this (Swift 3):

let cstorage = HTTPCookieStorage.shared
if let cookies = cstorage.cookies(for: url) {
    for cookie in cookies {
        cstorage.deleteCookie(cookie)
    }
}
like image 128
Eric Aya Avatar answered Sep 22 '22 14:09

Eric Aya