209 lines
8.6 KiB
Swift
209 lines
8.6 KiB
Swift
//
|
|
// IntroVC.swift
|
|
// WebAppUIKitBase
|
|
//
|
|
// Created by Sean Kim on 10/21/24.
|
|
//
|
|
|
|
import UIKit
|
|
import Alamofire
|
|
|
|
import SnapKit
|
|
import CoreLocation
|
|
|
|
class IntroVC: UIViewController {
|
|
|
|
override func viewDidLoad() {
|
|
super.viewDidLoad()
|
|
CommonUtils.shared.locationDelegate = self
|
|
}
|
|
override func viewDidAppear(_ animated: Bool) {
|
|
super.viewDidAppear(animated)
|
|
if isIllegalDevice() {
|
|
self.makeUIAlert(title: "안내",
|
|
message: "변경된 OS를 사용하는 기기는 서비스를 이용할 수 없습니다.",
|
|
okTitle: "확인") { _ in
|
|
exit(1)
|
|
}
|
|
} else {
|
|
if NetworkReachabilityManager.default?.isReachable == false {
|
|
self.makeUIAlert(title: "서비스 연결 문제 발생",
|
|
message: """
|
|
네트워크 문제로 서비스에 연결하지 못하였습니다.
|
|
네트워크 상태를 확인후 다시 실행해주세요.
|
|
""",
|
|
okTitle: "확인") { _ in
|
|
exit(1)
|
|
}
|
|
} else {
|
|
self.checkAppVersion()
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
private func checkAppVersion() {
|
|
Task {
|
|
do {
|
|
// VER_URL, VER_PARAM, VER_HEADERS는 사용자의 설정에 맞춰야 함
|
|
let result = try await CommonUtils.shared.afGET(url:VER_URL,
|
|
param: VER_PARAM,
|
|
headers: VER_HEADERS)
|
|
printLog("Success : \(result)")
|
|
let response = CommonUtils.shared.jsonToType("\(result)", as: VersionResponse.self)
|
|
|
|
if let code = response?.status.code, code == "000" {
|
|
if let currentVer = Bundle.main.infoDictionary?["CFBundleShortVersionString"] as? String,
|
|
let finalVer = response?.data.finalVer, let forceVer = response?.data.forceVer,
|
|
let checkVer = response?.data.checkVer, let forceUpdtYn = response?.data.forceUpdtYn
|
|
{
|
|
switch self.versionCompare(currentVer, finalVer) {
|
|
case .equal, .bigger: // 업데이트 처리 필요 없음
|
|
CommonUtils.shared.checkLocationPermission()
|
|
case .smaller:
|
|
switch self.versionCompare(currentVer, forceVer) {
|
|
case .equal, .bigger:
|
|
if forceUpdtYn == "P" {// PASS라서 P 한건데 Y 해도 된다.
|
|
self.makeUITwoAlert(title: "업데이트 안내",
|
|
message: "최신 버전이 새로 나왔어요\n지금 업데이트하시겠어요?",
|
|
okTitle: "지금 업데이트",
|
|
okAction: { _ in
|
|
let appStoreURL = URL(string: "http://www.naver.com")!
|
|
UIApplication.shared.open(appStoreURL, options: [:], completionHandler: nil)
|
|
exit(1)
|
|
}, cancelTitle: "나중에") { _ in
|
|
CommonUtils.shared.checkLocationPermission()
|
|
}
|
|
} else {
|
|
CommonUtils.shared.checkLocationPermission()
|
|
}
|
|
case .smaller:
|
|
self.makeUIAlert(title: "업데이트 안내",
|
|
message: "앱을 사용하시려면\n최신버전으로 업데이트 해주세요",
|
|
okTitle: "지금 업데이트") { _ in
|
|
let appStoreURL = URL(string: "http://www.naver.com")!
|
|
UIApplication.shared.open(appStoreURL, options: [:], completionHandler: nil)
|
|
exit(1)
|
|
}
|
|
}
|
|
}
|
|
}
|
|
else {
|
|
throw NSError(domain: "com.version.API",
|
|
code: Int(response?.status.code ?? "") ?? -1,
|
|
userInfo: [NSLocalizedDescriptionKey: "Version is Wrong"])
|
|
}
|
|
} else {
|
|
throw NSError(domain: "com.version.API",
|
|
code: Int(response?.status.code ?? "") ?? -1,
|
|
userInfo: [NSLocalizedDescriptionKey: "Version is Wrong"])
|
|
}
|
|
} catch {
|
|
printLog("App Check ERROR: \(error)")
|
|
self.makeUIAlert(title: "서비스 연결 문제 발생",
|
|
message: """
|
|
일시적인 장애 또는 네트워크 문제로
|
|
서비스에 연결하지 못하였습니다.
|
|
문제가 계속될 경우 고객센터로 문의해 주세요
|
|
""",
|
|
okTitle: "확인") { _ in
|
|
exit(1)
|
|
}
|
|
}
|
|
}
|
|
}
|
|
/// compareVer에 비교를 할 문자열을 넣어주면 된다.
|
|
///
|
|
/// [결과 해석: 현재 버전이 비교 버전보다 (RESULT) 하다.]
|
|
private func versionCompare(_ currentVer: String, _ compareVer: String) -> CompareVersion {
|
|
let currentArray = currentVer.components(separatedBy: ["."]).map {Int($0) ?? 0}
|
|
let compareArray = compareVer.components(separatedBy: ["."]).map {Int($0) ?? 0}
|
|
|
|
printLog("Ver current: \(currentArray)")
|
|
printLog("Ver force: \(compareArray)")
|
|
|
|
for i in 0 ..< currentArray.count {
|
|
if currentArray[i] > compareArray[i] {
|
|
// 현재 버전이 비교하려는 버전보다 큰 경우 == 그냥 일반 동작을 시키면 된다.
|
|
return .bigger
|
|
} else if currentArray[i] < compareArray[i] {
|
|
// 현재 버전이 비교하려는 버전보다 작은 경우 == 업데이트 조건 처리
|
|
return .smaller
|
|
}
|
|
}
|
|
|
|
// 현재 버전이 비교 버전과 동일
|
|
return .equal
|
|
}
|
|
|
|
private func moveToWeb() {
|
|
let VC = MainWebVC()
|
|
if let windowScene = UIApplication.shared.connectedScenes.first as? UIWindowScene,
|
|
let window = windowScene.windows.first {
|
|
window.rootViewController = VC
|
|
}
|
|
}
|
|
}
|
|
|
|
extension IntroVC: LocationDelegate {
|
|
|
|
func checkPermission(_ type: Bool) {
|
|
if type {
|
|
// CommonUtils.CommonUtils.shared.saveUdData("Y", forKey: "locationYn")
|
|
} else {
|
|
// CommonUtils.CommonUtils.shared.saveUdData("N", forKey: "locationYn")
|
|
self.moveToWeb()
|
|
}
|
|
}
|
|
|
|
func getLocation(_ location: CLLocation) {
|
|
CommonUtils.shared.locationManager.stopUpdatingLocation()
|
|
let lat = location.coordinate.latitude
|
|
let lng = location.coordinate.longitude
|
|
CommonUtils.shared.lastLocation = location
|
|
printLog("Intro \(String(describing: CommonUtils.shared.lastLocation))")
|
|
printLog("Intro Delegate = lattitude : \(lat) longitude : \(lng)")
|
|
printLog("위치 권한 허용 > 웹뷰 start")
|
|
self.moveToWeb()
|
|
}
|
|
}
|
|
|
|
|
|
|
|
enum CompareVersion: Int {
|
|
case equal = 0
|
|
case bigger
|
|
case smaller
|
|
}
|
|
|
|
class VersionResponse: Codable {
|
|
let status: Status
|
|
let data: VersionData
|
|
}
|
|
/// API 확인 변수
|
|
///
|
|
/// code: API 정상 확인 코드 (e.g. 000: 정상)
|
|
///
|
|
/// message: 코드에 대한 설명
|
|
class Status: Codable {
|
|
let code, message: String
|
|
|
|
}
|
|
|
|
/// API 데이터 변수
|
|
///
|
|
/// finaclVer: 현재 가장 최신 버전
|
|
///
|
|
/// forceVer: 이 버전보다 미만의 버전은 강제 업데이트 시행
|
|
///
|
|
/// checkVer: 개발용 및 업데이트 관련 버전
|
|
///
|
|
/// forceUpdYn: P(Y) 등의 값일 시 finalVer보다 미만의 경우 선택 업데이트 동작 시행
|
|
///
|
|
/// remark: 현재 버전 관련한 설명
|
|
class VersionData: Codable {
|
|
let finalVer, forceVer, checkVer: String?
|
|
let forceUpdtYn: String?
|
|
let remark: String?
|
|
}
|