Skip to content

Commit c792f5d

Browse files
authored
웹뷰 쿠키 관련 문제 수정 (#216)
* reset color scheme in the init phase Apply SwiftFormat changes * make cookie store persistent
1 parent 872ef13 commit c792f5d

File tree

3 files changed

+25
-2
lines changed

3 files changed

+25
-2
lines changed

SNUTT-2022/SNUTT/Extensions/ColorScheme.swift

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,3 +31,18 @@ extension ColorScheme {
3131
return nil
3232
}
3333
}
34+
35+
extension UIUserInterfaceStyle {
36+
func toColorScheme() -> ColorScheme {
37+
switch self {
38+
case .light:
39+
return .light
40+
case .dark:
41+
return .dark
42+
case .unspecified:
43+
return .light
44+
@unknown default:
45+
return .light
46+
}
47+
}
48+
}

SNUTT-2022/SNUTT/Views/Components/WebViews/WebViewProtocol.swift

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ extension WebView {
2424

2525
extension WKWebView {
2626
convenience init(cookies: [HTTPCookie]) {
27-
let dataStore = WKWebsiteDataStore.nonPersistent()
27+
let dataStore = WKWebsiteDataStore.default()
2828
let configuration = WKWebViewConfiguration()
2929
for cookie in cookies {
3030
dataStore.httpCookieStore.setCookie(cookie)
@@ -33,8 +33,12 @@ extension WKWebView {
3333
self.init(frame: .zero, configuration: configuration)
3434
}
3535

36+
var cookieStore: WKHTTPCookieStore {
37+
configuration.websiteDataStore.httpCookieStore
38+
}
39+
3640
func setCookie(name: String, value: String) {
3741
guard let cookie = NetworkConfiguration.getCookie(name: name, value: value) else { return }
38-
configuration.websiteDataStore.httpCookieStore.setCookie(cookie)
42+
cookieStore.setCookie(cookie)
3943
}
4044
}

SNUTT-2022/SNUTT/Views/Scenes/ReviewScene.swift

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,10 @@ struct ReviewScene: View {
2020
self.viewModel = viewModel
2121
_detailId = detailId
2222
self.isMainWebView = isMainWebView
23+
24+
/// It's too early to access `colorScheme` environment variable during the init phase.
25+
/// Use the system color scheme instead.
26+
eventSignal?.send(.colorSchemeChange(to: UITraitCollection.current.userInterfaceStyle.toColorScheme()))
2327
}
2428

2529
private var eventSignal: PassthroughSubject<WebViewEventType, Never>? {

0 commit comments

Comments
 (0)