Skip to content

Commit

Permalink
[Add] #311 앱스토어에 등록된 앱의 최신 버전을 가져오는 함수
Browse files Browse the repository at this point in the history
  • Loading branch information
isakatty committed May 26, 2024
1 parent abc58dd commit 976c89e
Showing 1 changed file with 51 additions and 0 deletions.
51 changes: 51 additions & 0 deletions Projects/App/Sources/AppStoreCheck.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
//
// 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()

/// 앱스토어에 등록된 앱의 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) {
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()
}
}

0 comments on commit 976c89e

Please sign in to comment.