151 lines
		
	
	
		
			5.6 KiB
		
	
	
	
		
			Swift
		
	
	
	
	
	
			
		
		
	
	
			151 lines
		
	
	
		
			5.6 KiB
		
	
	
	
		
			Swift
		
	
	
	
	
	
//
 | 
						|
//  SplashView.swift
 | 
						|
//  SodaLive
 | 
						|
//
 | 
						|
//  Created by klaus on 2023/08/09.
 | 
						|
//
 | 
						|
 | 
						|
import SwiftUI
 | 
						|
import FirebaseRemoteConfig
 | 
						|
 | 
						|
struct SplashView: View {
 | 
						|
    @State private var isShowForcedUpdatePopup = false
 | 
						|
    @State private var isShowUpdatePopup = false
 | 
						|
    @State private var isShowMaintenancePopup = false
 | 
						|
    
 | 
						|
    @StateObject var liveViewModel = LiveViewModel()
 | 
						|
    
 | 
						|
    var body: some View {
 | 
						|
        ZStack(alignment: .top) {
 | 
						|
            Image("splash_bg")
 | 
						|
                .resizable()
 | 
						|
                .scaledToFill()
 | 
						|
                .edgesIgnoringSafeArea(.all)
 | 
						|
            
 | 
						|
            VStack(spacing: 6) {
 | 
						|
                Image("splash_text1")
 | 
						|
                Image("splash_text2")
 | 
						|
            }
 | 
						|
            .padding(.top, screenSize().height * 615 / 2337)
 | 
						|
            
 | 
						|
            if isShowMaintenancePopup {
 | 
						|
                SodaDialog(
 | 
						|
                    title: "안내",
 | 
						|
                    desc: "서비스 점검중입니다.",
 | 
						|
                    confirmButtonTitle: "확인",
 | 
						|
                    confirmButtonAction: { isShowMaintenancePopup = false }
 | 
						|
                )
 | 
						|
            }
 | 
						|
            
 | 
						|
            if isShowUpdatePopup {
 | 
						|
                SodaDialog(
 | 
						|
                    title: "업데이트",
 | 
						|
                    desc: "최신 업데이트가 있습니다.\n업데이트 하시겠습니까?",
 | 
						|
                    confirmButtonTitle: "업데이트",
 | 
						|
                    confirmButtonAction: {
 | 
						|
                        UIApplication.shared.open(URL(string: "https://apps.apple.com/us/app/id6461721697?mt=8")!, options: [:])
 | 
						|
                    },
 | 
						|
                    cancelButtonTitle: "다음에",
 | 
						|
                    cancelButtonAction: {
 | 
						|
                        DispatchQueue.main.asyncAfter(deadline: .now() + 0.5) {
 | 
						|
                            AppState.shared.setAppStep(step: .main)
 | 
						|
                        }
 | 
						|
                    }
 | 
						|
                )
 | 
						|
            }
 | 
						|
            
 | 
						|
            if isShowForcedUpdatePopup {
 | 
						|
                SodaDialog(
 | 
						|
                    title: "업데이트",
 | 
						|
                    desc: "필수 업데이트가 있습니다.\n업데이트 후 사용가능합니다.",
 | 
						|
                    confirmButtonTitle: "업데이트",
 | 
						|
                    confirmButtonAction: {
 | 
						|
                        UIApplication.shared.open(URL(string: "https://apps.apple.com/us/app/id6461721697?mt=8")!, options: [:])
 | 
						|
                    }
 | 
						|
                )
 | 
						|
            }
 | 
						|
        }
 | 
						|
        .onAppear {
 | 
						|
            DispatchQueue.main.asyncAfter(deadline: .now() + 0.5) {
 | 
						|
                AppState.shared.isChangeAdultContentVisible = false
 | 
						|
            }
 | 
						|
            fetchLastestVersion()
 | 
						|
        }
 | 
						|
    }
 | 
						|
    
 | 
						|
    private func fetchLastestVersion() {
 | 
						|
        let remoteConfig = RemoteConfig.remoteConfig()
 | 
						|
        let configSettings = RemoteConfigSettings()
 | 
						|
        configSettings.minimumFetchInterval = 60
 | 
						|
        remoteConfig.configSettings = configSettings
 | 
						|
        
 | 
						|
        remoteConfig.fetch { status, error in
 | 
						|
            if status == .success {
 | 
						|
                remoteConfig.activate { changed, error in
 | 
						|
                    let isMaintenance = remoteConfig["is_maintenance"].boolValue
 | 
						|
                    if isMaintenance {
 | 
						|
                        isShowMaintenancePopup = true
 | 
						|
                    } else {
 | 
						|
                        checkAppVersion(latestVersion: remoteConfig["ios_latest_version"].stringValue)
 | 
						|
                    }
 | 
						|
                }
 | 
						|
            } else {
 | 
						|
                nextAppStep()
 | 
						|
            }
 | 
						|
        }
 | 
						|
    }
 | 
						|
    
 | 
						|
    private func nextAppStep() {
 | 
						|
        DispatchQueue.main.asyncAfter(deadline: .now() + 0.7) {
 | 
						|
            withAnimation {
 | 
						|
                if !UserDefaults.string(forKey: UserDefaultsKey.token).trimmingCharacters(in: .whitespacesAndNewlines).isEmpty {
 | 
						|
                    if AppState.shared.pushRoomId > 0 {
 | 
						|
                        liveViewModel.enterLiveRoom(roomId: AppState.shared.pushRoomId)
 | 
						|
                    } else if AppState.shared.pushChannelId > 0 {
 | 
						|
                        AppState.shared.setAppStep(step: .creatorDetail(userId: AppState.shared.pushChannelId))
 | 
						|
                    } else if AppState.shared.pushAudioContentId > 0 {
 | 
						|
                        AppState.shared.setAppStep(step: .contentDetail(contentId: AppState.shared.pushAudioContentId))
 | 
						|
                    } else if AppState.shared.pushSeriesId > 0 {
 | 
						|
                        AppState.shared.setAppStep(step: .seriesDetail(seriesId: AppState.shared.pushSeriesId))
 | 
						|
                    } else {
 | 
						|
                        AppState.shared.setAppStep(step: .main)
 | 
						|
                    }
 | 
						|
                } else {
 | 
						|
                    AppState.shared.setAppStep(step: .main)
 | 
						|
                }
 | 
						|
            }
 | 
						|
        }
 | 
						|
    }
 | 
						|
    
 | 
						|
    private func checkAppVersion(latestVersion: String?) {
 | 
						|
        let version = Bundle.main.infoDictionary?["CFBundleShortVersionString"] as? String
 | 
						|
        
 | 
						|
        if let latestVersion = latestVersion, let version = version {
 | 
						|
            let latestVersions = latestVersion.split(separator: ".")
 | 
						|
            let versions = version.split(separator: ".")
 | 
						|
            
 | 
						|
            let latestMajor = Int(latestVersions[0])!
 | 
						|
            let latestMinor = Int(latestVersions[1])!
 | 
						|
            let latestPatch = Int(latestVersions[2])!
 | 
						|
            
 | 
						|
            let major = Int(versions[0])!
 | 
						|
            let minor = Int(versions[1])!
 | 
						|
            let patch = Int(versions[2])!
 | 
						|
            
 | 
						|
            if latestMajor > major || (latestMajor == major && latestMinor > minor) {
 | 
						|
                self.isShowForcedUpdatePopup = true
 | 
						|
            } else if latestMajor == major && latestMinor == minor && latestPatch > patch {
 | 
						|
                self.isShowUpdatePopup = true
 | 
						|
            } else {
 | 
						|
                nextAppStep()
 | 
						|
            }
 | 
						|
        } else {
 | 
						|
            nextAppStep()
 | 
						|
        }
 | 
						|
    }
 | 
						|
}
 | 
						|
 | 
						|
#Preview {
 | 
						|
    SplashView()
 | 
						|
}
 |