Skip to content

Commit

Permalink
Merge pull request #168 from TeamBeMe/feature/#165
Browse files Browse the repository at this point in the history
์ž๋™ ์—…๋ฐ์ดํŠธ
  • Loading branch information
qodhrkawk authored Feb 11, 2021
2 parents 139469d + 84d1c6e commit 6d0df76
Show file tree
Hide file tree
Showing 3 changed files with 113 additions and 0 deletions.
4 changes: 4 additions & 0 deletions BeMe/BeMe.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -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 */; };
Expand Down Expand Up @@ -335,6 +336,7 @@
EC71C83425A5A41800F51FEC /* HomePageDataService.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = HomePageDataService.swift; sourceTree = "<group>"; };
EC71C84025A5B1BA00F51FEC /* HomeNewQuestionData.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = HomeNewQuestionData.swift; sourceTree = "<group>"; };
EC71C84B25A7769B00F51FEC /* ShittyImageCropVC.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ShittyImageCropVC.swift; sourceTree = "<group>"; };
EC730F7C25D4DECF003E09CC /* AppstoreCheck.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AppstoreCheck.swift; sourceTree = "<group>"; };
EC737F18259D867A0035207F /* CustomTodayCardView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = CustomTodayCardView.swift; sourceTree = "<group>"; };
EC737F1B259D8B9E0035207F /* CustomAddCardView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = CustomAddCardView.swift; sourceTree = "<group>"; };
EC737F20259DB2C40035207F /* FollowUpperCVC.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = FollowUpperCVC.swift; sourceTree = "<group>"; };
Expand Down Expand Up @@ -1239,6 +1241,7 @@
EC813F2E2599A15200BBCE25 /* LaunchScreen.storyboard */,
EC813F312599A15200BBCE25 /* Info.plist */,
D41B2D4725C2B7DE007CD08B /* GoogleService-Info.plist */,
EC730F7C25D4DECF003E09CC /* AppstoreCheck.swift */,
);
path = BeMe;
sourceTree = "<group>";
Expand Down Expand Up @@ -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 */,
Expand Down
41 changes: 41 additions & 0 deletions BeMe/BeMe/AppDelegate.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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
}
Expand Down
68 changes: 68 additions & 0 deletions BeMe/BeMe/AppstoreCheck.swift
Original file line number Diff line number Diff line change
@@ -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

}

}

0 comments on commit 6d0df76

Please sign in to comment.