Skip to content

Commit

Permalink
1.3.3
Browse files Browse the repository at this point in the history
  • Loading branch information
knottx committed Mar 11, 2022
1 parent 83948bb commit cf9739f
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 22 deletions.
2 changes: 1 addition & 1 deletion AppStoreManager.podspec
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
Pod::Spec.new do |spec|

spec.name = "AppStoreManager"
spec.version = "1.3.2"
spec.version = "1.3.3"
spec.summary = "A new version checking framework in Swift."

spec.homepage = "https://knottx.github.io"
Expand Down
4 changes: 2 additions & 2 deletions AppStoreManager.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -381,7 +381,7 @@
"@executable_path/Frameworks",
"@loader_path/Frameworks",
);
MARKETING_VERSION = 1.3.2;
MARKETING_VERSION = 1.3.3;
PRODUCT_BUNDLE_IDENTIFIER = com.knottx.AppStoreManager;
PRODUCT_NAME = "$(TARGET_NAME:c99extidentifier)";
SKIP_INSTALL = YES;
Expand Down Expand Up @@ -410,7 +410,7 @@
"@executable_path/Frameworks",
"@loader_path/Frameworks",
);
MARKETING_VERSION = 1.3.2;
MARKETING_VERSION = 1.3.3;
PRODUCT_BUNDLE_IDENTIFIER = com.knottx.AppStoreManager;
PRODUCT_NAME = "$(TARGET_NAME:c99extidentifier)";
SKIP_INSTALL = YES;
Expand Down
31 changes: 17 additions & 14 deletions Sources/AppStoreManager/AppStoreManager.swift
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@

import UIKit

public enum VersionCheckType:Int {
public enum VersionCheckType: Int {
case immediately = 0
case daily = 1
case weekly = 7
Expand All @@ -24,13 +24,13 @@ public class AppStoreManager {

public static let shared = AppStoreManager()

var title:String = AppStoreManagerConstant.alertTitle
var message:String? = AppStoreManagerConstant.alertMessage
var title: String = AppStoreManagerConstant.alertTitle
var message: String? = AppStoreManagerConstant.alertMessage

var skipButtonTitle:String = AppStoreManagerConstant.skipButtonTitle
var updateButtonTitle:String = AppStoreManagerConstant.updateButtonTitle
var skipButtonTitle: String = AppStoreManagerConstant.skipButtonTitle
var updateButtonTitle: String = AppStoreManagerConstant.updateButtonTitle

var lastVersionCheckDate:Date? {
var lastVersionCheckDate: Date? {
didSet{
UserDefaults.standard.set(self.lastVersionCheckDate, forKey: AppStoreDefaults.storedVersionCheckDate)
UserDefaults.standard.synchronize()
Expand All @@ -39,11 +39,11 @@ public class AppStoreManager {

let bundleId = Bundle.main.bundleIdentifier ?? ""

var currentInstalledVersion:String? {
var currentInstalledVersion: String? {
return Bundle.main.object(forInfoDictionaryKey: "CFBundleShortVersionString") as? String
}

var appStoreResult:AppStoreResult?
var appStoreResult: AppStoreResult?

init() {
self.lastVersionCheckDate = UserDefaults.standard.object(forKey: AppStoreDefaults.storedVersionCheckDate) as? Date
Expand Down Expand Up @@ -75,7 +75,7 @@ public class AppStoreManager {
task.resume()
}

public func checkNewVersion(_ type:VersionCheckType, isAvailable: @escaping (Bool) -> ()) {
public func checkNewVersion(_ type: VersionCheckType, isAvailable: @escaping (Bool) -> ()) {
self.getStoreVersion { [weak self] (result) in
if let currentInstalledVersion = self?.currentInstalledVersion,
let appStoreVersion = result?.version {
Expand Down Expand Up @@ -107,7 +107,10 @@ public class AppStoreManager {
}
}

public func checkNewVersionAndShowAlert(_ type:VersionCheckType,at vc:UIViewController, canSkip:Bool, preferredStyle: UIAlertController.Style = .alert) {
public func checkNewVersionAndShowAlert(_ type: VersionCheckType,
at vc: UIViewController,
canSkip: Bool,
preferredStyle: UIAlertController.Style = .alert) {
self.getStoreVersion { [weak self] (result) in
if let currentInstalledVersion = self?.currentInstalledVersion,
let appStoreVersion = result?.version {
Expand All @@ -126,17 +129,17 @@ public class AppStoreManager {

//MARK: - Alert

public func configureAlert(title:String?, message: String?) {
public func configureAlert(title: String?, message: String?) {
self.title = title ?? AppStoreManagerConstant.alertTitle
self.message = message
}

public func configureAlert(updateButtonTitle:String?, skipButtonTitle:String?) {
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: AppStoreManagerConstant.skipButtonTitle, style: .cancel) { (_) in
Expand Down Expand Up @@ -167,7 +170,7 @@ public class AppStoreManager {
}
}

func openAppStore(id appStoreId:Int) {
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)
Expand Down
12 changes: 7 additions & 5 deletions Sources/AppStoreManager/AppStoreManagerModels.swift
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,14 @@
import Foundation

struct AppStoreResponse: Decodable {
var resultCount:Int?
var results:[AppStoreResult]
let resultCount: Int?
let results: [AppStoreResult]
}

struct AppStoreResult: Decodable {
var trackId:Int?
var version:String?
var currentVersionReleaseDate:Date?
let trackId: Int?
let version: String?
let currentVersionReleaseDate: Date?

private enum CodingKeys: String, CodingKey {
case trackId
Expand All @@ -29,6 +29,8 @@ struct AppStoreResult: Decodable {
self.version = try? container.decodeIfPresent(String.self, forKey: .version)
if let date = try? container.decodeIfPresent(String.self, forKey: .currentVersionReleaseDate) {
self.currentVersionReleaseDate = date.toDate(with: "yyyy-MM-dd'T'HH:mm:ssZ")
} else {
self.currentVersionReleaseDate = nil
}
}

Expand Down

0 comments on commit cf9739f

Please sign in to comment.