Skip to content

Commit

Permalink
fix deployment target
Browse files Browse the repository at this point in the history
  • Loading branch information
knottx committed Nov 28, 2022
1 parent 6d82a4c commit b227969
Show file tree
Hide file tree
Showing 8 changed files with 80 additions and 58 deletions.
34 changes: 34 additions & 0 deletions .swiftformat
Original file line number Diff line number Diff line change
@@ -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
2 changes: 1 addition & 1 deletion AppStoreManager.podspec
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
12 changes: 6 additions & 6 deletions AppStoreManager.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
archiveVersion = 1;
classes = {
};
objectVersion = 50;
objectVersion = 52;
objects = {

/* Begin PBXBuildFile section */
Expand Down Expand Up @@ -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 = (
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand All @@ -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",
Expand Down Expand Up @@ -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",
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,6 @@ AppStoreManager.shared.configureAlert(updateButtonTitle: <String?>, skipButtonTi

## 📋 Requirements

* iOS 10.0+
* iOS 11.0+
* Xcode 11+
* Swift 5.1+
73 changes: 35 additions & 38 deletions Sources/AppStoreManager/AppStoreManager.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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) {
Expand All @@ -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) {
Expand All @@ -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)
Expand All @@ -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
Expand All @@ -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
6 changes: 0 additions & 6 deletions Sources/AppStoreManager/AppStoreManagerConstant.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -37,5 +32,4 @@ extension String {
let date = dateFormatter.date(from: self)
return date
}

}
5 changes: 2 additions & 3 deletions Sources/AppStoreManager/AppStoreManagerModels.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -33,5 +33,4 @@ struct AppStoreResult: Decodable {
self.currentVersionReleaseDate = nil
}
}

}
4 changes: 1 addition & 3 deletions Tests/AppStoreManagerTests/AppStoreManagerTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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.
}
Expand All @@ -29,5 +28,4 @@ class AppStoreManagerTests: XCTestCase {
// Put the code you want to measure the time of here.
}
}

}

0 comments on commit b227969

Please sign in to comment.