-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- 업데이트 판단: 현재 기기의 앱 버전과 앱스토어 버전을 비교해서, 앱스토어 버전이 크다면 업데이트 - 업데이트 체크 시점: 앱 시작될 경우, ScenePhase가 .active될 경우 - 알랏 틴트 색상 강제 적용
- Loading branch information
Showing
3 changed files
with
81 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
// | ||
// AppVersionManager.swift | ||
// ILSANG | ||
// | ||
// Created by Lee Jinhee on 2/5/25. | ||
// | ||
|
||
import UIKit | ||
|
||
final class AppVersionManager { | ||
static let shared = AppVersionManager() | ||
private let appStoreOpenUrlStr = "itms-apps://itunes.apple.com/app/apple-store/6504427618" | ||
|
||
private init() { } | ||
|
||
func isUpdateAvailable() async throws -> Bool { | ||
guard let info = Bundle.main.infoDictionary, | ||
let currentVersion = info["CFBundleShortVersionString"] as? String, // 현재 버전 가져오기 | ||
let identifier = info["CFBundleIdentifier"] as? String, // 앱 번들아이디 가져오기 | ||
let url = URL(string: "http://itunes.apple.com/kr/lookup?bundleId=\(identifier)") else { | ||
throw VersionError.invalidBundleInfo | ||
} | ||
|
||
let (data, _) = try await URLSession.shared.data(from: url) // 비동기 네트워크 요청 | ||
guard let json = try JSONSerialization.jsonObject(with: data, options: []) as? [String: Any], // 네트워크 응답 파싱 | ||
let result = (json["results"] as? [[String: Any]])?.first, | ||
let appStoreVersion = result["version"] as? String else { | ||
throw VersionError.invalidResponse | ||
} | ||
|
||
return currentVersion.compare(appStoreVersion, options: .numeric) == .orderedAscending // 현재 앱의 버전과 앱스토어 버전을 비교해서 업데이트 가능 여부 반환 | ||
} | ||
|
||
// 앱 스토어로 이동 | ||
func openAppStore() { | ||
guard let url = URL(string: appStoreOpenUrlStr) else { return } | ||
if UIApplication.shared.canOpenURL(url) { | ||
UIApplication.shared.open(url, options: [:], completionHandler: nil) | ||
} | ||
} | ||
} | ||
|
||
enum VersionError: Error { | ||
case invalidResponse, invalidBundleInfo | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters