티스토리 뷰

Swift

URLSession 쿠키 삭제하기

진태우 2018. 5. 23. 15:25

로그아웃시 세션을 지우지 않으면 로그아웃이 되지 않는 현상이 있었다.

간단하게 모든 세션을 지우는 코드를 적어보았다.

// 설치된 날짜 가져오는 코드
let urlToDocumentsFolder: URL? = FileManager.default.urls(for: .documentDirectory, in: .userDomainMask).last
let installDate = try? FileManager.default.attributesOfItem(atPath: (urlToDocumentsFolder?.path)!)[.creationDate] as! Date
        
// 설치된 날짜부터 지금까지의 cookie all clear
URLSession.shared.configuration.httpCookieStorage?.removeCookies(since: installDate!)


댓글
공지사항
최근에 올라온 글
최근에 달린 댓글
Total
Today
Yesterday
링크
«   2025/02   »
1
2 3 4 5 6 7 8
9 10 11 12 13 14 15
16 17 18 19 20 21 22
23 24 25 26 27 28
글 보관함