-
Notifications
You must be signed in to change notification settings - Fork 0
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 [#181] 앱 버전 업데이트 알림 구현 #182
Merged
Merged
Changes from 3 commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
722d489
[Feat] #181 - AppStore 버전 체크 코드 구현
yeonsu0-0 7b2e94a
[Feat] #181 - 앱 버전 확인 후 알림 띄우는 기능 구현
yeonsu0-0 1b9a5e3
[Feat] #181 - 버전 업데이트 알림 메세지 Literals로 구현
yeonsu0-0 7b90879
[Delete] #181 - 테스트 코드 삭제
yeonsu0-0 41950b9
[Feat] #181 - 코드리뷰 반영
yeonsu0-0 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 |
---|---|---|
|
@@ -10,7 +10,7 @@ import UIKit | |
import KakaoSDKAuth | ||
|
||
class SceneDelegate: UIResponder, UIWindowSceneDelegate { | ||
|
||
var window: UIWindow? | ||
|
||
func scene(_ scene: UIScene, willConnectTo session: UISceneSession, options connectionOptions: UIScene.ConnectionOptions) { | ||
|
@@ -34,6 +34,7 @@ class SceneDelegate: UIResponder, UIWindowSceneDelegate { | |
self.window?.rootViewController = navigationController | ||
} | ||
self.window?.makeKeyAndVisible() | ||
self.checkAndUpdateIfNeeded() | ||
} | ||
} | ||
|
||
|
@@ -44,35 +45,81 @@ class SceneDelegate: UIResponder, UIWindowSceneDelegate { | |
} | ||
} | ||
} | ||
|
||
func sceneDidDisconnect(_ scene: UIScene) { | ||
// Called as the scene is being released by the system. | ||
// This occurs shortly after the scene enters the background, or when its session is discarded. | ||
// Release any resources associated with this scene that can be re-created the next time the scene connects. | ||
// The scene may re-connect later, as its session was not necessarily discarded (see `application:didDiscardSceneSessions` instead). | ||
} | ||
|
||
func sceneDidBecomeActive(_ scene: UIScene) { | ||
// Called when the scene has moved from an inactive state to an active state. | ||
// Use this method to restart any tasks that were paused (or not yet started) when the scene was inactive. | ||
} | ||
|
||
func sceneWillResignActive(_ scene: UIScene) { | ||
// Called when the scene will move from an active state to an inactive state. | ||
// This may occur due to temporary interruptions (ex. an incoming phone call). | ||
} | ||
|
||
func sceneWillEnterForeground(_ scene: UIScene) { | ||
// Called as the scene transitions from the background to the foreground. | ||
// Use this method to undo the changes made on entering the background. | ||
self.checkAndUpdateIfNeeded() | ||
} | ||
|
||
func sceneDidEnterBackground(_ scene: UIScene) { | ||
// Called as the scene transitions from the foreground to the background. | ||
// Use this method to save data, release shared resources, and store enough scene-specific state information | ||
// to restore the scene back to its current state. | ||
} | ||
|
||
|
||
} | ||
|
||
|
||
|
||
func checkAndUpdateIfNeeded() { | ||
AppStoreCheckManager().latestVersion { marketingVersion in | ||
DispatchQueue.main.async { | ||
guard let marketingVersion = marketingVersion else { | ||
print("앱스토어 버전을 찾지 못했습니다.") | ||
return | ||
} | ||
|
||
let currentProjectVersion = AppStoreCheckManager.appVersion ?? "" | ||
|
||
let splitMarketingVersion = marketingVersion.split(separator: ".").map { $0 } | ||
|
||
let splitCurrentProjectVersion = currentProjectVersion.split(separator: ".").map { $0 } | ||
|
||
if splitCurrentProjectVersion.count > 0 && splitMarketingVersion.count > 0 { | ||
|
||
if splitCurrentProjectVersion[0] < splitMarketingVersion[0] { | ||
self.showUpdateAlert(version: marketingVersion) | ||
|
||
} else if splitCurrentProjectVersion[1] < splitMarketingVersion[1] { | ||
self.showUpdateAlert(version: marketingVersion) | ||
|
||
} else { | ||
self.showUpdateAlert(version: marketingVersion) | ||
} | ||
} | ||
} | ||
} | ||
} | ||
|
||
func showUpdateAlert(version: String) { | ||
let alert = UIAlertController( | ||
title: StringLiterals.VersionUpdate.versionTitle, | ||
message: StringLiterals.VersionUpdate.versionMessage, | ||
preferredStyle: .alert | ||
) | ||
|
||
let updateAction = UIAlertAction(title: "지금 업데이트", style: .default) { _ in | ||
AppStoreCheckManager().openAppStore() | ||
} | ||
|
||
let cancelAction = UIAlertAction(title: "나중에", style: .destructive, handler: nil) | ||
|
||
[ cancelAction, updateAction ].forEach { alert.addAction($0) } | ||
window?.rootViewController?.present(alert, animated: true, completion: nil) | ||
} | ||
} | ||
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. P3 |
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
42 changes: 42 additions & 0 deletions
42
DontBe-iOS/DontBe-iOS/Global/Shared/AppStoreCheckManager.swift
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,42 @@ | ||
// | ||
// AppStoreCheckManager.swift | ||
// DontBe-iOS | ||
// | ||
// Created by yeonsu on 4/24/24. | ||
// | ||
|
||
import UIKit | ||
|
||
class AppStoreCheckManager { | ||
|
||
static let appVersion = Bundle.main.infoDictionary?["CFBundleShortVersionString"] as? String | ||
static let buildNumber = Bundle.main.infoDictionary?["CFBundleVersion"] as? String | ||
static let appStoreOpenUrlString = "itms-apps://itunes.apple.com/app/apple-store/6475622329" | ||
|
||
func latestVersion(completion: @escaping (String?) -> Void) { | ||
let appleID = "6475622329" | ||
guard let url = URL(string: "https://itunes.apple.com/lookup?id=\(appleID)&country=kr") else { | ||
completion(nil) | ||
return | ||
} | ||
|
||
URLSession.shared.dataTask(with: url) { (data, response, error) in | ||
guard let data = data, error == nil, | ||
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) | ||
}.resume() | ||
} | ||
|
||
func openAppStore() { | ||
guard let url = URL(string: AppStoreCheckManager.appStoreOpenUrlString) else { return } | ||
if UIApplication.shared.canOpenURL(url) { | ||
UIApplication.shared.open(url, options: [:], completionHandler: nil) | ||
} | ||
} | ||
} |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
P3
앱스토어 체크해주는 라이브러리가 있군요!!