Skip to content

Commit 6a2ebe1

Browse files
authored
Add app metadata cookie for webview (#217)
add app metadata cookie for webview
1 parent c792f5d commit 6a2ebe1

File tree

3 files changed

+15
-15
lines changed

3 files changed

+15
-15
lines changed

SNUTT-2022/SNUTT/Repositories/NetworkConfiguration.swift

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@ struct NetworkConfiguration {
1212
static let serverBaseURL: String = Bundle.main.infoDictionary?["API_SERVER_URL"] as! String
1313
static let serverV1BaseURL: String = serverBaseURL + "/v1"
1414
static let snuevBaseURL: String = Bundle.main.infoDictionary?["SNUEV_WEB_URL"] as! String
15-
static let apiKey: String = Bundle.main.infoDictionary?["API_KEY"] as! String
1615

1716
static func getCookie(name: String, value: String) -> HTTPCookie? {
1817
return HTTPCookie(properties: [
@@ -25,11 +24,15 @@ struct NetworkConfiguration {
2524
}
2625

2726
static func getCookiesFrom(accessToken: String) -> [HTTPCookie] {
28-
guard let apiKeyCookie = getCookie(name: "x-access-apikey", value: NetworkConfiguration.apiKey),
29-
let tokenCookie = getCookie(name: "x-access-token", value: accessToken),
30-
let deviceTypeCookie = getCookie(name: "x-os-type", value: AppMetadata.osType.value ?? "ios")
27+
guard let tokenCookie = getCookie(name: "x-access-token", value: accessToken),
28+
let apiKeyCookie = getCookie(name: AppMetadata.apiKey.key, value: AppMetadata.apiKey.value),
29+
let osTypeCookie = getCookie(name: AppMetadata.osType.key, value: AppMetadata.osType.value),
30+
let osVersionCookie = getCookie(name: AppMetadata.osVersion.key, value: AppMetadata.osVersion.value),
31+
let appVersionCookie = getCookie(name: AppMetadata.appVersion.key, value: AppMetadata.appVersion.value),
32+
let appTypeCookie = getCookie(name: AppMetadata.appType.key, value: AppMetadata.appType.value),
33+
let buildNumberCookie = getCookie(name: AppMetadata.buildNumber.key, value: AppMetadata.buildNumber.value)
3134
else { return [] }
3235

33-
return [apiKeyCookie, tokenCookie, deviceTypeCookie]
36+
return [apiKeyCookie, tokenCookie, osTypeCookie, osVersionCookie, appVersionCookie, appTypeCookie, buildNumberCookie]
3437
}
3538
}

SNUTT-2022/SNUTT/Repositories/NetworkUtils.swift

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -34,10 +34,10 @@ final class Interceptor: RequestInterceptor {
3434
enum AppMetadata: CaseIterable {
3535
case appVersion, appType, osType, osVersion, apiKey, buildNumber
3636

37-
var value: String? {
37+
var value: String {
3838
switch self {
3939
case .appVersion:
40-
return Bundle.main.object(forInfoDictionaryKey: "CFBundleShortVersionString") as? String
40+
return (Bundle.main.object(forInfoDictionaryKey: "CFBundleShortVersionString") as? String) ?? "9.9.9"
4141
case .appType:
4242
#if DEBUG
4343
return "debug"
@@ -49,9 +49,9 @@ enum AppMetadata: CaseIterable {
4949
case .osVersion:
5050
return UIDevice.current.systemVersion
5151
case .apiKey:
52-
return NetworkConfiguration.apiKey
52+
return Bundle.main.infoDictionary?["API_KEY"] as! String
5353
case .buildNumber:
54-
return Bundle.main.object(forInfoDictionaryKey: kCFBundleVersionKey as String) as? String
54+
return (Bundle.main.object(forInfoDictionaryKey: kCFBundleVersionKey as String) as? String) ?? "999"
5555
}
5656
}
5757

SNUTT-2022/SNUTT/ViewModels/SettingViewModel.swift

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -92,12 +92,9 @@ class SettingViewModel: BaseViewModel, ObservableObject {
9292
}
9393

9494
var versionString: String {
95-
guard let appVersion = AppMetadata.appVersion.value,
96-
let buildNumber = AppMetadata.buildNumber.value,
97-
let appType = AppMetadata.appType.value
98-
else {
99-
return "버전 정보 없음"
100-
}
95+
let appVersion = AppMetadata.appVersion.value
96+
let buildNumber = AppMetadata.buildNumber.value
97+
let appType = AppMetadata.appType.value
10198
return "v\(appVersion)-\(appType).\(buildNumber)"
10299
}
103100

0 commit comments

Comments
 (0)