투케이2K

360. (ios/swift5) 웹뷰 (WKWebview) WKWebsiteDataStore 에 저장된 쿠키 및 세션 확인 - getAllCookies 본문

IOS

360. (ios/swift5) 웹뷰 (WKWebview) WKWebsiteDataStore 에 저장된 쿠키 및 세션 확인 - getAllCookies

투케이2K 2023. 11. 2. 08:15
반응형

[개발 환경 설정]

개발 툴 : XCODE

개발 언어 : SWIFT5

 

[소스 코드]

 

                // ----------------------------------
                // [쿠키 및 세션 확인]
                // ----------------------------------
                WKWebsiteDataStore.default().httpCookieStore.getAllCookies { (cookies) in
                    S_Log._D_(description: S_FinalMsg.LOG_Status_Check_Res, data: [
                        "URL :: \(String(describing: self.main_webview?.url?.description ?? ""))",
                        "설 명 :: WKWebsiteDataStore 저장된 쿠키 확인",
                        "cookies :: \(cookies)"
                    ])
                }
                // ----------------------------------
                if self.main_webview != nil {
                    if #available(iOS 11.0, *) {
                        self.main_webview!.configuration.websiteDataStore.httpCookieStore.getAllCookies { cookies in
                            S_Log._D_(description: S_FinalMsg.LOG_Status_Check_Res, data: [
                                "URL :: \(String(describing: self.main_webview?.url?.description ?? ""))",
                                "설 명 :: 웹뷰 저장된 쿠키 확인",
                                "cookies :: \(cookies)"
                            ])
                        }
                    }
                    else {
                        S_Log._D_(description: S_FinalMsg.LOG_Status_Check_Res, data: [
                            "URL :: \(String(describing: self.main_webview?.url?.description ?? ""))",
                            "Error :: iOS 11.0 미만 디바이스 >> 웹뷰 저장된 쿠키 값 확인 실패"
                        ])
                    }
                }
                // ----------------------------------

 

반응형
Comments