header-img
Info :
  1. 'CS > iOS, Swift' 카테고리의 다른 글

기록용으로 남겨놓는 것으로, 더 깔끔하게 구현할 수 있는 방법이 존재하겠지만.. 하나하나 파라미터로 다 넘기기 싫고 함수의 길이도 길어지는게 싫어서 아래와 같이 저는 구현했습니다. 아래 함수를 통해 만들어진 쿠키로 웹뷰에 넣었을 때 정상 작동했습니다. 

import UIKit
class CookieUtil {
private let path: String = "/"
let cookieDomain = "_"
private enum cookieBaseName: String {
case appId = "_"
// ...
}
func getAppCookie() -> HTTPCookie? {
guard let cookie = HTTPCookie(properties: [
.domain: cookieDomain,
.path: path,
.name: cookieBaseName.appId.rawValue,
.value: AppInfo.appID.rawValue
]) else {
return nil
}
return cookie
}
func getTokenCookie(token: String) -> HTTPCookie? {
guard let cookie = HTTPCookie(properties: [
.domain: cookieDomain,
.path: path,
.name: "비공개",
.value: token
]) else {
return nil
}
return cookie
}
func getUidCookie() -> HTTPCookie? {
guard let cookie = HTTPCookie(properties: [
.domain: cookieDomain,
.path: path,
.name: "비공개",
.value: UIDevice.current.identifierForVendor!.uuidString
]) else {
return nil
}
return cookie
}
func logCookie(_ cookie: HTTPCookie) {
print("""
---------------------------------------------------------
cookie : \(cookie.name)
value : \(cookie.value)
expires date : \(String(describing: cookie.expiresDate))
domain : \(cookie.domain)
---------------------------------------------------------
""")
}
}

'CS > iOS, Swift' 카테고리의 다른 글

[iOS] unix timestamp swift  (0) 2023.04.07
[iOS] 서버 통신 Base Service  (0) 2023.04.07
[iOS] 키체인 유틸  (0) 2023.04.07
[iOS] 해싱  (0) 2023.04.07
[iOS] Framework, Library RnD  (0) 2023.04.07
더보기
CS/iOS, Swift