Swift3.1 수동으로 쿠키 만들기

1462 단어
MARK: - HTTPCookiePropertyKey에 정의된 키 상수는 다음과 같습니다.
public static let name: HTTPCookiePropertyKey

public static let value: HTTPCookiePropertyKey

public static let originURL: HTTPCookiePropertyKey

public static let version: HTTPCookiePropertyKey

public static let domain: HTTPCookiePropertyKey

public static let path: HTTPCookiePropertyKey

public static let secure: HTTPCookiePropertyKey

public static let expires: HTTPCookiePropertyKey

public static let comment: HTTPCookiePropertyKey

public static let commentURL: HTTPCookiePropertyKey

public static let discard: HTTPCookiePropertyKey

public static let maximumAge: HTTPCookiePropertyKey

public static let port: HTTPCookiePropertyKey

MARK: - 쿠키 쓰기
class func writeCookie() {
    //     1 
    let expires: TimeInterval = 60 * 60 * 24 * 365
    
    //           cookie   
    var properties: [HTTPCookiePropertyKey : Any] = [:]
    properties[.name] = "cookieName"
    properties[.path] = "/"
    properties[.value] = "cookieValue"
    properties[.secure] = false
    properties[.domain] = "domain"
    properties[.version] = 0
    properties[.expires] = Date.init(timeIntervalSinceNow: expires)
    
    //    cookie  ,       
    let cookie = HTTPCookie.init(properties: properties)
    if let cookie = cookie {
        //   cookie,       /Library/Cookies
        HTTPCookieStorage.shared.setCookie(cookie)
    }
}

좋은 웹페이지 즐겨찾기