-
Notifications
You must be signed in to change notification settings - Fork 3
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Feat/#311 앱스토어의 앱 버전과 기존 앱의 버전을 추적하여 강제 업데이트 기능 #313
base: dev
Are you sure you want to change the base?
Changes from 4 commits
abc58dd
976c89e
a215197
f5dd3c8
5cefc75
b8e4353
f1f9aad
edffe09
f0ba96c
3637db5
b407074
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
// | ||
// AppStoreCheck.swift | ||
// App | ||
// | ||
// Created by Jisoo Ham on 5/26/24. | ||
// Copyright © 2024 Pepsi-Club. All rights reserved. | ||
// | ||
|
||
import UIKit | ||
|
||
import Core | ||
|
||
public final class AppStoreCheck { | ||
|
||
/// 프로젝트 버전 | ||
let appVersion = String.getCurrentVersion() | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 사용되지 않는 변수인데 남겨두신 이유가 있으신가요? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. sceneDelegate에서 가져다 쓰려고 뒀는데 scene에서도 또 변수 만들어서 썼네요 🥲 수정하겠습니다 ~ |
||
|
||
/// 앱스토어에 등록된 앱의 ID | ||
static let appleID = Bundle.main.object(forInfoDictionaryKey: "APPLE_ID") as? String | ||
|
||
/// 앱스토어 연결 링크 | ||
static let appStoreURLString | ||
= "itms-apps://itunes.apple.com/app/apple-store/" | ||
|
||
/// 앱스토어에 등록된 최신 버전 가져오는 함수 | ||
static public func latestVersion(completion: @escaping (String?) -> Void) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. async await 말고 컴플리션 핸들러를 쓰신 이유가 있을까요 ?.? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 아아 app delegate 에서 쓰일 코드가 아닌데 async-await 해놨던걸 거기서 쓰다가 문제가 생겨서 completion으로 변경하고 scene delegate를 하다가 다시 수정한다는걸 잊어버렸어요 🫠 |
||
guard let appleID = AppStoreCheck.appleID, | ||
let url = URL( | ||
string: "https://itunes.apple.com/lookup?id=\(appleID)&country=kr" | ||
) | ||
else { return } | ||
|
||
let task = URLSession.shared.dataTask(with: url) { data, response, err in | ||
guard let data, | ||
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 { | ||
completion(nil) | ||
return | ||
} | ||
|
||
completion(appStoreVersion) | ||
} | ||
|
||
task.resume() | ||
} | ||
|
||
/// URL을 통해 앱스토어 오픈 | ||
static public func openAppStore() { | ||
guard let appleID, | ||
let url = URL(string: AppStoreCheck.appStoreURLString + appleID) | ||
else { return } | ||
|
||
if UIApplication.shared.canOpenURL(url) { | ||
UIApplication.shared.open(url) | ||
} | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -20,7 +20,7 @@ final class SceneDelegate: UIResponder, UIWindowSceneDelegate { | |
var deeplinkHandler: DeeplinkHandler? | ||
|
||
func scene( | ||
_ scene: UIScene, | ||
_ scene: UIScene, | ||
willConnectTo session: UISceneSession, | ||
options connectionOptions: UIScene.ConnectionOptions | ||
) { | ||
|
@@ -37,6 +37,7 @@ final class SceneDelegate: UIResponder, UIWindowSceneDelegate { | |
) | ||
appCoordinator?.start() | ||
window?.makeKeyAndVisible() | ||
self.checkAndUpdateIfNeeded() | ||
deeplinkHandler = .init(appCoordinator: appCoordinator) | ||
if let url = connectionOptions.urlContexts.first?.url { | ||
deeplinkHandler?.handleUrl(url: url) | ||
|
@@ -52,7 +53,9 @@ final class SceneDelegate: UIResponder, UIWindowSceneDelegate { | |
func sceneWillResignActive(_ scene: UIScene) { | ||
} | ||
|
||
/// 앱이 Foreground로 전환될때 실행될 함수 | ||
func sceneWillEnterForeground(_ scene: UIScene) { | ||
self.checkAndUpdateIfNeeded() | ||
} | ||
|
||
func sceneDidEnterBackground(_ scene: UIScene) { | ||
|
@@ -66,5 +69,48 @@ final class SceneDelegate: UIResponder, UIWindowSceneDelegate { | |
deeplinkHandler?.handleUrl(url: url) | ||
} | ||
} | ||
|
||
private func checkAndUpdateIfNeeded() { | ||
AppStoreCheck.latestVersion { marketingVersion in | ||
DispatchQueue.main.async { | ||
guard let marketingVersion else { return } | ||
|
||
/// 현재 기기 버전 | ||
let currentProjectVersion = String.getCurrentVersion() | ||
|
||
/// .을 기준으로 나눔 | ||
let splitMarketingVersion = marketingVersion.split(separator: ".").map { $0 } | ||
let splitCurrentProjectVersion = currentProjectVersion.split(separator: ".").map { $0 } | ||
|
||
if splitCurrentProjectVersion.count > 0 && splitMarketingVersion.count > 0 { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 이 구문이 필수적으로 필요한지 궁금합니다! There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 82, 83은 [1.2.3] 이렇게 오는걸 .을 기준으로 나누기 위해서 필요하고, |
||
// Major 버전만을 비교 | ||
if splitCurrentProjectVersion[0] < splitMarketingVersion[0] { | ||
self.showUpdateAlert(version: marketingVersion) | ||
} else { | ||
print("현재 최신 버전입니다.") | ||
} | ||
|
||
} | ||
} | ||
} | ||
} | ||
|
||
private func showUpdateAlert(version: String) { | ||
let alert = UIAlertController( | ||
title: "업데이트 알림", | ||
message: "더 나은 서비스를 위해 업데이트 되었어요 ! 업데이트 해주세요.", | ||
preferredStyle: .alert | ||
) | ||
|
||
let alertAction = UIAlertAction( | ||
title: "업데이트", | ||
style: .default) { _ in | ||
AppStoreCheck.openAppStore() | ||
} | ||
|
||
alert.addAction(alertAction) | ||
window?.rootViewController?.present(alert, animated: true) | ||
|
||
} | ||
} | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
APPLE_ID가 유저의 apple 계정 id로 유추되어서 APPSTORE_ID와 같이 표현하면 어떨까요?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
변경하겠습니다 !