diff --git a/BeMe/BeMe.xcodeproj/project.pbxproj b/BeMe/BeMe.xcodeproj/project.pbxproj index b93aef2..edffacf 100644 --- a/BeMe/BeMe.xcodeproj/project.pbxproj +++ b/BeMe/BeMe.xcodeproj/project.pbxproj @@ -110,6 +110,7 @@ EC71C83525A5A41800F51FEC /* HomePageDataService.swift in Sources */ = {isa = PBXBuildFile; fileRef = EC71C83425A5A41800F51FEC /* HomePageDataService.swift */; }; EC71C84125A5B1BA00F51FEC /* HomeNewQuestionData.swift in Sources */ = {isa = PBXBuildFile; fileRef = EC71C84025A5B1BA00F51FEC /* HomeNewQuestionData.swift */; }; EC71C84C25A7769B00F51FEC /* ShittyImageCropVC.swift in Sources */ = {isa = PBXBuildFile; fileRef = EC71C84B25A7769B00F51FEC /* ShittyImageCropVC.swift */; }; + EC730F7D25D4DECF003E09CC /* AppstoreCheck.swift in Sources */ = {isa = PBXBuildFile; fileRef = EC730F7C25D4DECF003E09CC /* AppstoreCheck.swift */; }; EC737F19259D867A0035207F /* CustomTodayCardView.swift in Sources */ = {isa = PBXBuildFile; fileRef = EC737F18259D867A0035207F /* CustomTodayCardView.swift */; }; EC737F1C259D8B9E0035207F /* CustomAddCardView.swift in Sources */ = {isa = PBXBuildFile; fileRef = EC737F1B259D8B9E0035207F /* CustomAddCardView.swift */; }; EC737F21259DB2C40035207F /* FollowUpperCVC.swift in Sources */ = {isa = PBXBuildFile; fileRef = EC737F20259DB2C40035207F /* FollowUpperCVC.swift */; }; @@ -335,6 +336,7 @@ EC71C83425A5A41800F51FEC /* HomePageDataService.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = HomePageDataService.swift; sourceTree = ""; }; EC71C84025A5B1BA00F51FEC /* HomeNewQuestionData.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = HomeNewQuestionData.swift; sourceTree = ""; }; EC71C84B25A7769B00F51FEC /* ShittyImageCropVC.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ShittyImageCropVC.swift; sourceTree = ""; }; + EC730F7C25D4DECF003E09CC /* AppstoreCheck.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AppstoreCheck.swift; sourceTree = ""; }; EC737F18259D867A0035207F /* CustomTodayCardView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = CustomTodayCardView.swift; sourceTree = ""; }; EC737F1B259D8B9E0035207F /* CustomAddCardView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = CustomAddCardView.swift; sourceTree = ""; }; EC737F20259DB2C40035207F /* FollowUpperCVC.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = FollowUpperCVC.swift; sourceTree = ""; }; @@ -1239,6 +1241,7 @@ EC813F2E2599A15200BBCE25 /* LaunchScreen.storyboard */, EC813F312599A15200BBCE25 /* Info.plist */, D41B2D4725C2B7DE007CD08B /* GoogleService-Info.plist */, + EC730F7C25D4DECF003E09CC /* AppstoreCheck.swift */, ); path = BeMe; sourceTree = ""; @@ -1651,6 +1654,7 @@ EC71C84125A5B1BA00F51FEC /* HomeNewQuestionData.swift in Sources */, EC89E32E259C496C00DBAFE5 /* FollowMoreButtonCVC.swift in Sources */, EC89E339259C507300DBAFE5 /* UnderTabBarController.swift in Sources */, + EC730F7D25D4DECF003E09CC /* AppstoreCheck.swift in Sources */, D4E07CBC259F22C10075E616 /* DiffThoughtCVC.swift in Sources */, EC89E33F259C5EBB00DBAFE5 /* HomeCardCustomFlowLayout.swift in Sources */, D4344B2925AAC21E002858CF /* Comment.swift in Sources */, diff --git a/BeMe/BeMe/AppDelegate.swift b/BeMe/BeMe/AppDelegate.swift index a3405ab..6bd7447 100644 --- a/BeMe/BeMe/AppDelegate.swift +++ b/BeMe/BeMe/AppDelegate.swift @@ -13,6 +13,27 @@ import FirebaseRemoteConfig @main class AppDelegate: UIResponder, UIApplicationDelegate { + func appUpdate() { + + // id뒤에 값은 앱정보에 Apple ID에 써있는 숫자 + + if let url = URL(string: "itms-apps://itunes.apple.com/app/id1548760434"), UIApplication.shared.canOpenURL(url) { + + // 앱스토어로 이동 + + if #available(iOS 10.0, *) { + + UIApplication.shared.open(url, options: [:], completionHandler: nil) + + } else { + + UIApplication.shared.openURL(url) + + } + + } + + } func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool { @@ -30,6 +51,26 @@ class AppDelegate: UIResponder, UIApplicationDelegate { print("errrrrrr") } }) + + _ = try? AppStoreCheck.isUpdateAvailable { (update, error) in + + if let error = error { + + print(error) + + } else if let update = update { + + if update { + + self.appUpdate() + + return + + } + + } + + } return true } diff --git a/BeMe/BeMe/AppstoreCheck.swift b/BeMe/BeMe/AppstoreCheck.swift new file mode 100644 index 0000000..b0212ff --- /dev/null +++ b/BeMe/BeMe/AppstoreCheck.swift @@ -0,0 +1,68 @@ +// +// AppstoreCheck.swift +// BeMe +// +// Created by Yunjae Kim on 2021/02/10. +// + +import Foundation + +enum VersionError: Error { + case invalidResponse, invalidBundleInfo +} + + +class AppStoreCheck { + + static func isUpdateAvailable(completion: @escaping (Bool?, Error?) -> Void) throws -> URLSessionDataTask { + + 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 task = URLSession.shared.dataTask(with: url) { (data, response, error) in + + do { + + if let error = error { throw error } + + guard let data = data else { throw VersionError.invalidResponse } + + let json = try JSONSerialization.jsonObject(with: data, options: [.allowFragments]) as? [String: Any] + + guard let result = (json?["results"] as? [Any])?.first as? [String: Any], let version = result["version"] as? String else { + + throw VersionError.invalidResponse + + } + + let verFloat = NSString.init(string: version).floatValue + + let currentVerFloat = NSString.init(string: currentVersion).floatValue + + completion(verFloat > currentVerFloat, nil) // 현재 버전이 앱스토어 버전보다 큰지를 Bool값으로 반환 + + } catch { + + completion(nil, error) + + } + + } + + task.resume() + + return task + + } + +} +