diff --git a/GoldWars/GoldWars.xcodeproj/project.pbxproj b/GoldWars/GoldWars.xcodeproj/project.pbxproj index 9abc352..c286db4 100644 --- a/GoldWars/GoldWars.xcodeproj/project.pbxproj +++ b/GoldWars/GoldWars.xcodeproj/project.pbxproj @@ -54,7 +54,6 @@ C064E9A8246C0EA50022B228 /* LabelNode.swift in Sources */ = {isa = PBXBuildFile; fileRef = C064E9A7246C0EA50022B228 /* LabelNode.swift */; }; C064E9AA246C114C0022B228 /* LabelComponent.swift in Sources */ = {isa = PBXBuildFile; fileRef = C064E9A9246C114C0022B228 /* LabelComponent.swift */; }; C064E9AC246C151F0022B228 /* Label.swift in Sources */ = {isa = PBXBuildFile; fileRef = C064E9AB246C151F0022B228 /* Label.swift */; }; - C078408B24936C96006E4269 /* AppUpdater.swift in Sources */ = {isa = PBXBuildFile; fileRef = C078408A24936C96006E4269 /* AppUpdater.swift */; }; C099579C246C5E5C0016AA22 /* DataService.swift in Sources */ = {isa = PBXBuildFile; fileRef = C099579B246C5E5C0016AA22 /* DataService.swift */; }; /* End PBXBuildFile section */ @@ -121,7 +120,6 @@ C064E9A7246C0EA50022B228 /* LabelNode.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = LabelNode.swift; sourceTree = ""; }; C064E9A9246C114C0022B228 /* LabelComponent.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = LabelComponent.swift; sourceTree = ""; }; C064E9AB246C151F0022B228 /* Label.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Label.swift; sourceTree = ""; }; - C078408A24936C96006E4269 /* AppUpdater.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AppUpdater.swift; sourceTree = ""; }; C099579B246C5E5C0016AA22 /* DataService.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = DataService.swift; sourceTree = ""; }; /* End PBXFileReference section */ @@ -424,7 +422,6 @@ 3F745DF0246F48FC00CE7375 /* PlayerMoveType.swift in Sources */, 3EAD889524801B6A0048A10A /* RoundTimer.swift in Sources */, 3E67854024728368007B9DE4 /* CElements.swift in Sources */, - C078408B24936C96006E4269 /* AppUpdater.swift in Sources */, ABA03DA0244BD54F00A66916 /* Base.swift in Sources */, C064E9AC246C151F0022B228 /* Label.swift in Sources */, ABC0C3732481509300387B8F /* MapUtils.swift in Sources */, @@ -599,14 +596,14 @@ CODE_SIGN_ENTITLEMENTS = GoldWars/GoldWars.entitlements; CODE_SIGN_IDENTITY = "Apple Development"; CODE_SIGN_STYLE = Automatic; - CURRENT_PROJECT_VERSION = 4; + CURRENT_PROJECT_VERSION = 1; DEVELOPMENT_TEAM = DDKFQG46BQ; INFOPLIST_FILE = GoldWars/Info.plist; LD_RUNPATH_SEARCH_PATHS = ( "$(inherited)", "@executable_path/Frameworks", ); - MARKETING_VERSION = 1.0; + MARKETING_VERSION = 1.1; PRODUCT_BUNDLE_IDENTIFIER = de.hft.stuttgart.ip2.goldwars; PRODUCT_NAME = "$(TARGET_NAME)"; PROVISIONING_PROFILE_SPECIFIER = ""; @@ -622,14 +619,14 @@ CODE_SIGN_ENTITLEMENTS = GoldWars/GoldWars.entitlements; CODE_SIGN_IDENTITY = "Apple Development"; CODE_SIGN_STYLE = Automatic; - CURRENT_PROJECT_VERSION = 4; + CURRENT_PROJECT_VERSION = 1; DEVELOPMENT_TEAM = DDKFQG46BQ; INFOPLIST_FILE = GoldWars/Info.plist; LD_RUNPATH_SEARCH_PATHS = ( "$(inherited)", "@executable_path/Frameworks", ); - MARKETING_VERSION = 1.0; + MARKETING_VERSION = 1.1; PRODUCT_BUNDLE_IDENTIFIER = de.hft.stuttgart.ip2.goldwars; PRODUCT_NAME = "$(TARGET_NAME)"; PROVISIONING_PROFILE_SPECIFIER = ""; diff --git a/GoldWars/GoldWars/AppUpdater.swift b/GoldWars/GoldWars/AppUpdater.swift deleted file mode 100644 index 5e2895b..0000000 --- a/GoldWars/GoldWars/AppUpdater.swift +++ /dev/null @@ -1,124 +0,0 @@ -// -// AppUpdater.swift -// GoldWars -// -// Created by Tim Herbst on 12.06.20. -// Copyright © 2020 SP2. All rights reserved. -// -import UIKit - -enum VersionError: Error { - case invalidBundleInfo, invalidResponse -} - -class LookupResult: Decodable { - var results: [AppInfo] -} - -class AppInfo: Decodable { - var version: String - var trackViewUrl: String -} - -class AppUpdater: NSObject { - static let appUpdaterInstance = AppUpdater() - - private override init() { - - } - - private func getAppInfo(completion: @escaping (AppInfo?, Error?) -> Void) -> URLSessionDataTask? { - guard let identifier = Bundle.main.infoDictionary?["CFBundleIdentifier"] as? String, - let url = URL(string: "http://itunes.apple.com/lookup?bundleId=\(identifier)") else { - DispatchQueue.main.async { - completion(nil, VersionError.invalidBundleInfo) - } - return nil - } - let task = URLSession.shared.dataTask(with: url) { (data, response, error) in - do { - if error != nil { throw error! } - guard let data = data else { throw VersionError.invalidResponse } - - print("Data:::",data) - print("response###",response!) - - let result = try JSONDecoder().decode(LookupResult.self, from: data) - - let dictionary = try? JSONSerialization.jsonObject(with: data, options: .mutableLeaves) - - print("dictionary",dictionary!) - - - guard let info = result.results.first else { throw VersionError.invalidResponse } - print("result:::",result) - completion(info, nil) - } catch { - completion(nil, error) - } - } - task.resume() - print("task ******", task) - return task - } - - private func checkVersion(force: Bool) { - let info = Bundle.main.infoDictionary - let currentVersion = info?["CFBundleShortVersionString"] as? String - _ = getAppInfo { (info, error) in - let appStoreVersion = info?.version - if let error = error { - dump(error) - } else if appStoreVersion!.compare(currentVersion!, options: .numeric) { - DispatchQueue.main.async { - //TODO: Really need UIKit-Alert? -> replace keyWindow (deprecated) - let topController: UIViewController = UIApplication.shared.windows[0].rootViewController! - - topController.showAppUpdateAlert(Version: (info?.version)!, Force: force, AppURL: (info?.trackViewUrl)!) - //END TODO - } - } - } - } - func showUpdateWithConfirmation() { - checkVersion(force : false) - } - func showUpdateWithForce() { - checkVersion(force : true) - } -} -extension UIViewController { - fileprivate func showAppUpdateAlert( Version : String, Force: Bool, AppURL: String) { - print("AppURL:::::",AppURL) - - let bundleName = Bundle.main.infoDictionary!["CFBundleDisplayName"] as! String; - let alertMessage = "\(bundleName) Version \(Version) is available on AppStore." - let alertTitle = "New Version" - - - let alertController = UIAlertController(title: alertTitle, message: alertMessage, preferredStyle: .alert) - - - if !Force { - let notNowButton = UIAlertAction(title: "Not Now", style: .default) { (action:UIAlertAction) in - print("Don't Call API"); - } - alertController.addAction(notNowButton) - } - - let updateButton = UIAlertAction(title: "Update", style: .default) { (action:UIAlertAction) in - print("Call API"); - print("No update") - guard let url = URL(string: AppURL) else { - return - } - if #available(iOS 13.2, *) { - UIApplication.shared.open(url, options: [:], completionHandler: nil) - } else { - UIApplication.shared.openURL(url) - } - } - alertController.addAction(updateButton) - self.present(alertController, animated: true, completion: nil) - } -}