From b2279694b712d7d3beabde75dbfd90a46f905027 Mon Sep 17 00:00:00 2001 From: Knot Date: Mon, 28 Nov 2022 16:35:45 +0700 Subject: [PATCH] fix deployment target --- .swiftformat | 34 +++++++++ AppStoreManager.podspec | 2 +- AppStoreManager.xcodeproj/project.pbxproj | 12 +-- README.md | 2 +- Sources/AppStoreManager/AppStoreManager.swift | 73 +++++++++---------- .../AppStoreManagerConstant.swift | 6 -- .../AppStoreManagerModels.swift | 5 +- .../AppStoreManagerTests.swift | 4 +- 8 files changed, 80 insertions(+), 58 deletions(-) create mode 100644 .swiftformat diff --git a/.swiftformat b/.swiftformat new file mode 100644 index 0000000..5a3c532 --- /dev/null +++ b/.swiftformat @@ -0,0 +1,34 @@ +# file options + +--symlinks ignore +--swiftversion 5.1 + +# rules +--enable isEmpty +--disable andOperator +--disable wrapMultilineStatementBraces +--ifdef no-indent + +# format options + +--closingparen same-line +--commas inline +--comments indent +--decimalgrouping 3,5 +--exponentcase lowercase +--exponentgrouping disabled +--fractiongrouping disabled +--importgrouping testable-top +--operatorfunc no-space +--nospaceoperators ..<, ... +--selfrequired validate +--self insert +--stripunusedargs closure-only +--wraparguments after-first +--wrapcollections after-first +--wrapparameters after-first +--disable redundantReturn + +# excludes + +--exclude Pods, Package.swift \ No newline at end of file diff --git a/AppStoreManager.podspec b/AppStoreManager.podspec index be139ea..4cd6659 100644 --- a/AppStoreManager.podspec +++ b/AppStoreManager.podspec @@ -10,7 +10,7 @@ Pod::Spec.new do |spec| spec.source = { :git => "https://github.com/knottx/AppStoreManager.git", :tag => "#{spec.version}" } spec.swift_version = "5.1" - spec.ios.deployment_target = "10.0" + spec.ios.deployment_target = "11.0" spec.source_files = "Sources/AppStoreManager/**/*.swift" spec.requires_arc = true diff --git a/AppStoreManager.xcodeproj/project.pbxproj b/AppStoreManager.xcodeproj/project.pbxproj index 7833725..d80f7aa 100644 --- a/AppStoreManager.xcodeproj/project.pbxproj +++ b/AppStoreManager.xcodeproj/project.pbxproj @@ -3,7 +3,7 @@ archiveVersion = 1; classes = { }; - objectVersion = 50; + objectVersion = 52; objects = { /* Begin PBXBuildFile section */ @@ -176,7 +176,7 @@ }; }; buildConfigurationList = 1A38DD8B25A7F907003F396E /* Build configuration list for PBXProject "AppStoreManager" */; - compatibilityVersion = "Xcode 9.3"; + compatibilityVersion = "Xcode 11.0"; developmentRegion = en; hasScannedForEncodings = 0; knownRegions = ( @@ -293,7 +293,7 @@ GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; GCC_WARN_UNUSED_FUNCTION = YES; GCC_WARN_UNUSED_VARIABLE = YES; - IPHONEOS_DEPLOYMENT_TARGET = 10.0; + IPHONEOS_DEPLOYMENT_TARGET = 11.0; MTL_ENABLE_DEBUG_INFO = INCLUDE_SOURCE; MTL_FAST_MATH = YES; ONLY_ACTIVE_ARCH = YES; @@ -351,7 +351,7 @@ GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; GCC_WARN_UNUSED_FUNCTION = YES; GCC_WARN_UNUSED_VARIABLE = YES; - IPHONEOS_DEPLOYMENT_TARGET = 10.0; + IPHONEOS_DEPLOYMENT_TARGET = 11.0; MTL_ENABLE_DEBUG_INFO = NO; MTL_FAST_MATH = YES; SDKROOT = iphoneos; @@ -375,7 +375,7 @@ DYLIB_INSTALL_NAME_BASE = "@rpath"; INFOPLIST_FILE = Sources/AppStoreManager/Info.plist; INSTALL_PATH = "$(LOCAL_LIBRARY_DIR)/Frameworks"; - IPHONEOS_DEPLOYMENT_TARGET = 10.0; + IPHONEOS_DEPLOYMENT_TARGET = 11.0; LD_RUNPATH_SEARCH_PATHS = ( "$(inherited)", "@executable_path/Frameworks", @@ -404,7 +404,7 @@ DYLIB_INSTALL_NAME_BASE = "@rpath"; INFOPLIST_FILE = Sources/AppStoreManager/Info.plist; INSTALL_PATH = "$(LOCAL_LIBRARY_DIR)/Frameworks"; - IPHONEOS_DEPLOYMENT_TARGET = 10.0; + IPHONEOS_DEPLOYMENT_TARGET = 11.0; LD_RUNPATH_SEARCH_PATHS = ( "$(inherited)", "@executable_path/Frameworks", diff --git a/README.md b/README.md index e24ad85..b5e734b 100755 --- a/README.md +++ b/README.md @@ -64,6 +64,6 @@ AppStoreManager.shared.configureAlert(updateButtonTitle: , skipButtonTi ## 📋 Requirements -* iOS 10.0+ +* iOS 11.0+ * Xcode 11+ * Swift 5.1+ diff --git a/Sources/AppStoreManager/AppStoreManager.swift b/Sources/AppStoreManager/AppStoreManager.swift index 6ab426f..241b4f5 100644 --- a/Sources/AppStoreManager/AppStoreManager.swift +++ b/Sources/AppStoreManager/AppStoreManager.swift @@ -15,47 +15,46 @@ public enum VersionCheckType: Int { case weekly = 7 } -struct AppStoreDefaults { +enum AppStoreDefaults { static let storedVersionCheckDate = "storedVersionCheckDate" static let storedSkippedVersion = "storedSkippedVersion" } public class AppStoreManager { - public static let shared = AppStoreManager() - + var title: String = AppStoreManagerConstant.alertTitle var message: String? = AppStoreManagerConstant.alertMessage - + var skipButtonTitle: String = AppStoreManagerConstant.skipButtonTitle var updateButtonTitle: String = AppStoreManagerConstant.updateButtonTitle - + var lastVersionCheckDate: Date? { - didSet{ + didSet { UserDefaults.standard.set(self.lastVersionCheckDate, forKey: AppStoreDefaults.storedVersionCheckDate) UserDefaults.standard.synchronize() } } - + let bundleId = Bundle.main.bundleIdentifier ?? "" - + var currentInstalledVersion: String? { return Bundle.main.object(forInfoDictionaryKey: "CFBundleShortVersionString") as? String } - + var appStoreResult: AppStoreResult? - + init() { self.lastVersionCheckDate = UserDefaults.standard.object(forKey: AppStoreDefaults.storedVersionCheckDate) as? Date } - - func getStoreVersion(completion: @escaping (AppStoreResult?) -> ()) { + + func getStoreVersion(completion: @escaping (AppStoreResult?) -> Void) { guard let url = URL(string: "https://itunes.apple.com/lookup?bundleId=\(self.bundleId)") else { completion(nil) return } let session = URLSession(configuration: .default) - let task = session.dataTask(with: url) { [weak self] (data, response, error) in + let task = session.dataTask(with: url) { [weak self] data, _, error in if let er = error { self?.log(er.localizedDescription) completion(nil) @@ -67,16 +66,16 @@ public class AppStoreManager { self?.log("AppStore version: \(result.version ?? "")") self?.appStoreResult = result completion(result) - }else{ + } else { self?.appStoreResult = nil completion(nil) } } task.resume() } - - public func checkNewVersion(_ type: VersionCheckType, isAvailable: @escaping (Bool) -> ()) { - self.getStoreVersion { [weak self] (result) in + + public func checkNewVersion(_ type: VersionCheckType, isAvailable: @escaping (Bool) -> Void) { + self.getStoreVersion { [weak self] result in if let currentInstalledVersion = self?.currentInstalledVersion, let appStoreVersion = result?.version { switch currentInstalledVersion.compare(appStoreVersion, options: .numeric) { @@ -94,24 +93,24 @@ public class AppStoreManager { if Date.days(since: lastVersionCheckDate) >= type.rawValue { self?.lastVersionCheckDate = Date() isAvailable(true) - }else{ + } else { isAvailable(false) } } case .orderedDescending, .orderedSame: isAvailable(false) } - }else{ + } else { isAvailable(false) } } } - + public func checkNewVersionAndShowAlert(_ type: VersionCheckType, at vc: UIViewController, canSkip: Bool, preferredStyle: UIAlertController.Style = .alert) { - self.getStoreVersion { [weak self] (result) in + self.getStoreVersion { [weak self] result in if let currentInstalledVersion = self?.currentInstalledVersion, let appStoreVersion = result?.version { switch currentInstalledVersion.compare(appStoreVersion, options: .numeric) { @@ -121,31 +120,31 @@ public class AppStoreManager { case .orderedDescending, .orderedSame: break } - }else{ + } else { self?.log("Can't get Version") } } } - - //MARK: - Alert - + + // MARK: - Alert + public func configureAlert(title: String?, message: String?) { self.title = title ?? AppStoreManagerConstant.alertTitle self.message = message } - + public func configureAlert(updateButtonTitle: String?, skipButtonTitle: String?) { self.updateButtonTitle = updateButtonTitle ?? AppStoreManagerConstant.updateButtonTitle self.skipButtonTitle = skipButtonTitle ?? AppStoreManagerConstant.skipButtonTitle } - - public func showAlertUpdate(at vc:UIViewController, canSkip: Bool, preferredStyle: UIAlertController.Style = .alert) { + + public func showAlertUpdate(at vc: UIViewController, canSkip: Bool, preferredStyle: UIAlertController.Style = .alert) { DispatchQueue.main.async { [weak self] in let alertVc = UIAlertController(title: self?.title, message: self?.message, preferredStyle: preferredStyle) - let skip = UIAlertAction(title: self?.skipButtonTitle ?? AppStoreManagerConstant.skipButtonTitle, style: .cancel) { (_) in + let skip = UIAlertAction(title: self?.skipButtonTitle ?? AppStoreManagerConstant.skipButtonTitle, style: .cancel) { _ in // } - let update = UIAlertAction(title: self?.updateButtonTitle ?? AppStoreManagerConstant.updateButtonTitle, style: .default) { (_) in + let update = UIAlertAction(title: self?.updateButtonTitle ?? AppStoreManagerConstant.updateButtonTitle, style: .default) { _ in self?.openAppStore() } alertVc.addAction(update) @@ -155,12 +154,12 @@ public class AppStoreManager { vc.present(alertVc, animated: true, completion: nil) } } - + public func openAppStore() { if let appStoreId = self.appStoreResult?.trackId { self.openAppStore(id: appStoreId) - }else{ - self.getStoreVersion { [weak self] (result) in + } else { + self.getStoreVersion { [weak self] result in guard let appStoreId = result?.trackId else { self?.log("Can't get an AppId") return @@ -169,21 +168,19 @@ public class AppStoreManager { } } } - + func openAppStore(id appStoreId: Int) { if let url = URL(string: "https://itunes.apple.com/app/id\(appStoreId)"), UIApplication.shared.canOpenURL(url) { UIApplication.shared.open(url, options: [:], completionHandler: nil) - }else{ + } else { self.log("Can't open AppStore") } } - + func log(_ value: String) { print("📲: [AppStore] => \(value)") } - } - #endif diff --git a/Sources/AppStoreManager/AppStoreManagerConstant.swift b/Sources/AppStoreManager/AppStoreManagerConstant.swift index 24bdc55..5239e07 100644 --- a/Sources/AppStoreManager/AppStoreManagerConstant.swift +++ b/Sources/AppStoreManager/AppStoreManagerConstant.swift @@ -14,20 +14,15 @@ struct AppStoreManagerConstant { static let updateButtonTitle = "Update" } - extension Date { - static func days(since date: Date) -> Int { let calendar = Calendar(identifier: .gregorian) let components = calendar.dateComponents([.day], from: date, to: Date()) return components.day ?? 0 } - } - extension String { - func toDate(with format: String) -> Date? { let dateFormatter = DateFormatter() dateFormatter.calendar = Calendar(identifier: .gregorian) @@ -37,5 +32,4 @@ extension String { let date = dateFormatter.date(from: self) return date } - } diff --git a/Sources/AppStoreManager/AppStoreManagerModels.swift b/Sources/AppStoreManager/AppStoreManagerModels.swift index 6d4886c..ffbdfab 100644 --- a/Sources/AppStoreManager/AppStoreManagerModels.swift +++ b/Sources/AppStoreManager/AppStoreManagerModels.swift @@ -16,13 +16,13 @@ struct AppStoreResult: Decodable { let trackId: Int? let version: String? let currentVersionReleaseDate: Date? - + private enum CodingKeys: String, CodingKey { case trackId case version case currentVersionReleaseDate } - + init(from decoder: Decoder) throws { let container = try decoder.container(keyedBy: CodingKeys.self) self.trackId = try? container.decodeIfPresent(Int.self, forKey: .trackId) @@ -33,5 +33,4 @@ struct AppStoreResult: Decodable { self.currentVersionReleaseDate = nil } } - } diff --git a/Tests/AppStoreManagerTests/AppStoreManagerTests.swift b/Tests/AppStoreManagerTests/AppStoreManagerTests.swift index 2680e50..aad8ce0 100644 --- a/Tests/AppStoreManagerTests/AppStoreManagerTests.swift +++ b/Tests/AppStoreManagerTests/AppStoreManagerTests.swift @@ -5,11 +5,10 @@ // Created by Visarut Tippun on 8/1/21. // -import XCTest @testable import AppStoreManager +import XCTest class AppStoreManagerTests: XCTestCase { - override func setUpWithError() throws { // Put setup code here. This method is called before the invocation of each test method in the class. } @@ -29,5 +28,4 @@ class AppStoreManagerTests: XCTestCase { // Put the code you want to measure the time of here. } } - }