9
9
10
10
import UIKit
11
11
12
- public enum VersionCheckType : Int {
12
+ public enum VersionCheckType : Int {
13
13
case immediately = 0
14
14
case daily = 1
15
15
case weekly = 7
@@ -24,13 +24,13 @@ public class AppStoreManager {
24
24
25
25
public static let shared = AppStoreManager ( )
26
26
27
- var title : String = AppStoreManagerConstant . alertTitle
28
- var message : String ? = AppStoreManagerConstant . alertMessage
27
+ var title : String = AppStoreManagerConstant . alertTitle
28
+ var message : String ? = AppStoreManagerConstant . alertMessage
29
29
30
- var skipButtonTitle : String = AppStoreManagerConstant . skipButtonTitle
31
- var updateButtonTitle : String = AppStoreManagerConstant . updateButtonTitle
30
+ var skipButtonTitle : String = AppStoreManagerConstant . skipButtonTitle
31
+ var updateButtonTitle : String = AppStoreManagerConstant . updateButtonTitle
32
32
33
- var lastVersionCheckDate : Date ? {
33
+ var lastVersionCheckDate : Date ? {
34
34
didSet{
35
35
UserDefaults . standard. set ( self . lastVersionCheckDate, forKey: AppStoreDefaults . storedVersionCheckDate)
36
36
UserDefaults . standard. synchronize ( )
@@ -39,11 +39,11 @@ public class AppStoreManager {
39
39
40
40
let bundleId = Bundle . main. bundleIdentifier ?? " "
41
41
42
- var currentInstalledVersion : String ? {
42
+ var currentInstalledVersion : String ? {
43
43
return Bundle . main. object ( forInfoDictionaryKey: " CFBundleShortVersionString " ) as? String
44
44
}
45
45
46
- var appStoreResult : AppStoreResult ?
46
+ var appStoreResult : AppStoreResult ?
47
47
48
48
init ( ) {
49
49
self . lastVersionCheckDate = UserDefaults . standard. object ( forKey: AppStoreDefaults . storedVersionCheckDate) as? Date
@@ -75,7 +75,7 @@ public class AppStoreManager {
75
75
task. resume ( )
76
76
}
77
77
78
- public func checkNewVersion( _ type: VersionCheckType , isAvailable: @escaping ( Bool ) -> ( ) ) {
78
+ public func checkNewVersion( _ type: VersionCheckType , isAvailable: @escaping ( Bool ) -> ( ) ) {
79
79
self . getStoreVersion { [ weak self] ( result) in
80
80
if let currentInstalledVersion = self ? . currentInstalledVersion,
81
81
let appStoreVersion = result? . version {
@@ -107,7 +107,10 @@ public class AppStoreManager {
107
107
}
108
108
}
109
109
110
- public func checkNewVersionAndShowAlert( _ type: VersionCheckType , at vc: UIViewController , canSkip: Bool , preferredStyle: UIAlertController . Style = . alert) {
110
+ public func checkNewVersionAndShowAlert( _ type: VersionCheckType ,
111
+ at vc: UIViewController ,
112
+ canSkip: Bool ,
113
+ preferredStyle: UIAlertController . Style = . alert) {
111
114
self . getStoreVersion { [ weak self] ( result) in
112
115
if let currentInstalledVersion = self ? . currentInstalledVersion,
113
116
let appStoreVersion = result? . version {
@@ -126,17 +129,17 @@ public class AppStoreManager {
126
129
127
130
//MARK: - Alert
128
131
129
- public func configureAlert( title: String ? , message: String ? ) {
132
+ public func configureAlert( title: String ? , message: String ? ) {
130
133
self . title = title ?? AppStoreManagerConstant . alertTitle
131
134
self . message = message
132
135
}
133
136
134
- public func configureAlert( updateButtonTitle: String ? , skipButtonTitle: String ? ) {
137
+ public func configureAlert( updateButtonTitle: String ? , skipButtonTitle: String ? ) {
135
138
self . updateButtonTitle = updateButtonTitle ?? AppStoreManagerConstant . updateButtonTitle
136
139
self . skipButtonTitle = skipButtonTitle ?? AppStoreManagerConstant . skipButtonTitle
137
140
}
138
141
139
- public func showAlertUpdate( at vc: UIViewController , canSkip: Bool , preferredStyle: UIAlertController . Style = . alert) {
142
+ public func showAlertUpdate( at vc: UIViewController , canSkip: Bool , preferredStyle: UIAlertController . Style = . alert) {
140
143
DispatchQueue . main. async { [ weak self] in
141
144
let alertVc = UIAlertController ( title: self ? . title, message: self ? . message, preferredStyle: preferredStyle)
142
145
let skip = UIAlertAction ( title: AppStoreManagerConstant . skipButtonTitle, style: . cancel) { ( _) in
@@ -167,7 +170,7 @@ public class AppStoreManager {
167
170
}
168
171
}
169
172
170
- func openAppStore( id appStoreId: Int ) {
173
+ func openAppStore( id appStoreId: Int ) {
171
174
if let url = URL ( string: " https://itunes.apple.com/app/id \( appStoreId) " ) ,
172
175
UIApplication . shared. canOpenURL ( url) {
173
176
UIApplication . shared. open ( url, options: [ : ] , completionHandler: nil )
0 commit comments