Skip to content

Commit

Permalink
Add app metadata cookie for webview (#217)
Browse files Browse the repository at this point in the history
add app metadata cookie for webview
  • Loading branch information
shp7724 authored Feb 3, 2023
1 parent c792f5d commit 6a2ebe1
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 15 deletions.
13 changes: 8 additions & 5 deletions SNUTT-2022/SNUTT/Repositories/NetworkConfiguration.swift
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ struct NetworkConfiguration {
static let serverBaseURL: String = Bundle.main.infoDictionary?["API_SERVER_URL"] as! String
static let serverV1BaseURL: String = serverBaseURL + "/v1"
static let snuevBaseURL: String = Bundle.main.infoDictionary?["SNUEV_WEB_URL"] as! String
static let apiKey: String = Bundle.main.infoDictionary?["API_KEY"] as! String

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

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

return [apiKeyCookie, tokenCookie, deviceTypeCookie]
return [apiKeyCookie, tokenCookie, osTypeCookie, osVersionCookie, appVersionCookie, appTypeCookie, buildNumberCookie]
}
}
8 changes: 4 additions & 4 deletions SNUTT-2022/SNUTT/Repositories/NetworkUtils.swift
Original file line number Diff line number Diff line change
Expand Up @@ -34,10 +34,10 @@ final class Interceptor: RequestInterceptor {
enum AppMetadata: CaseIterable {
case appVersion, appType, osType, osVersion, apiKey, buildNumber

var value: String? {
var value: String {
switch self {
case .appVersion:
return Bundle.main.object(forInfoDictionaryKey: "CFBundleShortVersionString") as? String
return (Bundle.main.object(forInfoDictionaryKey: "CFBundleShortVersionString") as? String) ?? "9.9.9"
case .appType:
#if DEBUG
return "debug"
Expand All @@ -49,9 +49,9 @@ enum AppMetadata: CaseIterable {
case .osVersion:
return UIDevice.current.systemVersion
case .apiKey:
return NetworkConfiguration.apiKey
return Bundle.main.infoDictionary?["API_KEY"] as! String
case .buildNumber:
return Bundle.main.object(forInfoDictionaryKey: kCFBundleVersionKey as String) as? String
return (Bundle.main.object(forInfoDictionaryKey: kCFBundleVersionKey as String) as? String) ?? "999"
}
}

Expand Down
9 changes: 3 additions & 6 deletions SNUTT-2022/SNUTT/ViewModels/SettingViewModel.swift
Original file line number Diff line number Diff line change
Expand Up @@ -92,12 +92,9 @@ class SettingViewModel: BaseViewModel, ObservableObject {
}

var versionString: String {
guard let appVersion = AppMetadata.appVersion.value,
let buildNumber = AppMetadata.buildNumber.value,
let appType = AppMetadata.appType.value
else {
return "버전 정보 없음"
}
let appVersion = AppMetadata.appVersion.value
let buildNumber = AppMetadata.buildNumber.value
let appType = AppMetadata.appType.value
return "v\(appVersion)-\(appType).\(buildNumber)"
}

Expand Down

0 comments on commit 6a2ebe1

Please sign in to comment.