Skip to content
This repository has been archived by the owner on Apr 4, 2024. It is now read-only.

Commit

Permalink
Merge branch 'develop'
Browse files Browse the repository at this point in the history
  • Loading branch information
HongSJae committed Oct 6, 2023
2 parents 93cef4a + 3d0149f commit 9fcf76a
Show file tree
Hide file tree
Showing 8 changed files with 129 additions and 65 deletions.
68 changes: 39 additions & 29 deletions Projects/Feature/SplashFeature/Sources/SplashView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,45 @@ struct SplashView: View {
.resizable()
.frame(width: 200, height: 200)
}
.alert(isPresented: $viewModel.showUpdateAlert) {
if viewModel.forceAlert {
return Alert(
title: Text(viewModel.alertTitle),
message: Text(viewModel.alertMessage),
dismissButton: Alert.Button.destructive(
Text("확인"),
action: {
viewModel.openAppStore()
}
)
)
} else {
let reissue: () -> Void = {
viewModel.compareRefreshToke { authority in
appState.authority = authority
appState.sceneFlow = .main
} onError: { _ in
appState.sceneFlow = .auth
}
}

return Alert(
title: Text(viewModel.alertTitle),
message: Text(viewModel.alertMessage),
primaryButton: Alert.Button.destructive(
Text("확인"),
action: {
viewModel.openAppStore()
reissue()
}
),
secondaryButton: Alert.Button.cancel(
Text("취소"),
action: reissue
)
)
}
}
.onAppear {
viewModel.onAppear { authority in
appState.authority = authority
Expand All @@ -26,34 +65,5 @@ struct SplashView: View {
appState.sceneFlow = .auth
}
}
.alert(isPresented: $viewModel.showUpdateAlert) {
Alert(
title: Text(viewModel.alertTitle),
message: Text(viewModel.alertMessage),
primaryButton: Alert.Button.destructive(
Text("확인"),
action: {
viewModel.openAppStore()
appState.sceneFlow = .auth
}
),
secondaryButton: Alert.Button.cancel(
Text("취소")
)
)
}
.alert(isPresented: $viewModel.showUpdateForceAlert) {
Alert(
title: Text(viewModel.alertTitle),
message: Text(viewModel.alertMessage),
dismissButton: Alert.Button.destructive(
Text("확인"),
action: {
viewModel.openAppStore()
appState.sceneFlow = .auth
}
)
)
}
}
}
75 changes: 43 additions & 32 deletions Projects/Feature/SplashFeature/Sources/SplashViewModel.swift
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import UsersDomainInterface
final class SplashViewModel: BaseViewModel {
private let reissueTokenUseCase: any ReissueTokenUseCase
@Published var showUpdateAlert: Bool = false
@Published var showUpdateForceAlert: Bool = false
@Published var forceAlert: Bool = false
public var alertTitle = ""
public var alertMessage = ""
private let appleID = "6450888392"
Expand All @@ -23,46 +23,57 @@ final class SplashViewModel: BaseViewModel {
onError: @escaping (Error) -> Void
) {
update {
addCancellable(reissueTokenUseCase.execute()) { authority in
if authority {
onSuccess(.developer)
} else {
onSuccess(.student)
}
} onReceiveError: { error in
onError(error)
self.compareRefreshToke(onSuccess: onSuccess, onError: onError)
}
}

func compareRefreshToke(
onSuccess: @escaping (AuthorityType) -> Void,
onError: @escaping (Error) -> Void
) {
addCancellable(reissueTokenUseCase.execute()) { authority in
if authority {
onSuccess(.developer)
} else {
onSuccess(.student)
}
} onReceiveError: { error in
onError(error)
}
}

private func update(action: () -> Void) {
private func update(action: @escaping () -> Void) {
let appVersion = Bundle.main.infoDictionary?["CFBundleShortVersionString"] as? String
let urlString = "http://itunes.apple.com/lookup?id=\(self.appleID)&country=kr"

let latestVersion: String? = {
guard let url = URL(string: "http://itunes.apple.com/lookup?id=\(self.appleID)&country=kr"),
let data = try? Data(contentsOf: url),
let json = try? JSONSerialization.jsonObject(with: data, options: .allowFragments) as? [String: Any],
guard appVersion != "0.0.0" else { return action() }
guard let url = URL(string: urlString) else { return }
let urlRequest = URLRequest(url: url)
URLSession.shared.dataTask(with: urlRequest) { data, _, _ in
guard let json = try? JSONSerialization.jsonObject(with: data!, options: .allowFragments) as? [String: Any],
let results = json["results"] as? [[String: Any]],
let appStoreVersion = results[0]["version"] as? String else {
return nil
}
return appStoreVersion
}()

let marketingVersion = latestVersion!
let currentProjectVersion = appVersion!
let splitMarketingVersion = marketingVersion.split(separator: ".").map {$0}
let splitCurrentProjectVersion = currentProjectVersion.split(separator: ".").map {$0}
let marketingVersion = results[0]["version"] as? String else { return }
let currentProjectVersion = appVersion!
let splitMarketingVersion = marketingVersion.split(separator: ".").map {$0}
let splitCurrentProjectVersion = currentProjectVersion.split(separator: ".").map {$0}

alertTitle = "업데이트 알림"
alertMessage = "JOBIS의 새로운 버전이 있습니다.\n\(marketingVersion) 버전으로 업데이트 해주세요."
if splitCurrentProjectVersion[0] < splitMarketingVersion[0] {
showUpdateForceAlert.toggle()
} else if splitCurrentProjectVersion[1] < splitMarketingVersion[1] {
showUpdateForceAlert.toggle()
} else {
showUpdateAlert.toggle()
DispatchQueue.main.async {
self.alertTitle = "업데이트 알림"
self.alertMessage = "JOBIS의 새로운 버전이 있습니다.\n\(marketingVersion) 버전으로 업데이트 해주세요."
if splitCurrentProjectVersion[0] < splitMarketingVersion[0] {
self.showUpdateAlert.toggle()
self.forceAlert.toggle()
} else if splitCurrentProjectVersion[1] < splitMarketingVersion[1] {
self.showUpdateAlert.toggle()
self.forceAlert.toggle()
} else if splitCurrentProjectVersion[2] < splitMarketingVersion[2] {
self.showUpdateAlert.toggle()
} else {
action()
}
}
}
.resume()
}

func openAppStore() {
Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
{
"images" : [
{
"filename" : "Frame 20767.svg",
"idiom" : "universal",
"scale" : "1x"
},
{
"idiom" : "universal",
"scale" : "2x"
},
{
"idiom" : "universal",
"scale" : "3x"
}
],
"info" : {
"author" : "xcode",
"version" : 1
}
}
10 changes: 7 additions & 3 deletions Projects/Shared/DesignSystem/Sources/Image/JOBISIcon.swift
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,8 @@ public struct JOBISIcon: View {
case menu
case profile
case house
case militaryServiceExceptionIcon
case militaryExceptionOn
case militaryExceptionOff
case bookmarkOn
case bookmarkOff
case filterIcon
Expand Down Expand Up @@ -140,8 +141,11 @@ public struct JOBISIcon: View {
case .house:
return DesignSystemAsset.Icons.house.suiImage

case .militaryServiceExceptionIcon:
return DesignSystemAsset.Icons.militaryServiceExceptionIcon.suiImage
case .militaryExceptionOn:
return DesignSystemAsset.Icons.militaryExceptionOn.suiImage

case .militaryExceptionOff:
return DesignSystemAsset.Icons.militaryExceptionOff.suiImage

case .bookmarkOn:
return DesignSystemAsset.Icons.bookmarkOn.suiImage
Expand Down
6 changes: 5 additions & 1 deletion Projects/Shared/DesignSystem/Sources/Image/URLImage.swift
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,11 @@ public struct URLImage: View {

public init(imageURL urlString: String, shape: ImageShape) {
let baseURL = Environment.getUrlValue(key: .s3BaseUrl)
self.imageURL = baseURL.appendingPathComponent(urlString)
if urlString.contains(baseURL.description) {
imageURL = URL(string: urlString)
} else {
self.imageURL = baseURL.appendingPathComponent(urlString)
}

self.shape = shape
}
Expand Down

0 comments on commit 9fcf76a

Please sign in to comment.