-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathForceUpdateChecker.swift
73 lines (56 loc) · 2.17 KB
/
ForceUpdateChecker.swift
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
//
// ForceUpdateChecker.swift
// Call Signature
//
// Created by User on 13/07/2021.
// Copyright © 2021 Monty Mobile. All rights reserved.
//
import Foundation
import Firebase
protocol OnUpdateNeededListener {
func onUpdateNeeded(updateUrl : String)
func onNoUpdateNeeded()
}
class ForceUpdateChecker {
static let TAG = "ForceUpdateChecker"
static let FORCE_UPDATE_STORE_URL = "force_update_store_url"
static let FORCE_UPDATE_CURRENT_VERSION = "force_update_current_version"
static let FORCE_UPDATE_REQUIRED = "force_update_required"
var listener : OnUpdateNeededListener
init(listener : OnUpdateNeededListener) {
self.listener = listener
}
func check(){
let remoteConfig = RemoteConfig.remoteConfig()
let forceRequired = remoteConfig[ForceUpdateChecker.FORCE_UPDATE_REQUIRED].boolValue
print("\(ForceUpdateChecker.TAG) : forceRequired : \(forceRequired)")
if(forceRequired == true){
let currentVersion = remoteConfig[ForceUpdateChecker.FORCE_UPDATE_CURRENT_VERSION].stringValue
print("\(ForceUpdateChecker.TAG) : currentVersion: \(currentVersion!)")
if(currentVersion != nil){
let appVersion = getAppVersion()
if( currentVersion != appVersion){
let url = remoteConfig[ForceUpdateChecker.FORCE_UPDATE_STORE_URL].stringValue
if(url != nil){
listener.onUpdateNeeded(updateUrl: url! )
}
}
else {
listener.onNoUpdateNeeded()
}
}
else {
listener.onNoUpdateNeeded()
}
} else {
listener.onNoUpdateNeeded()
}
}
func getAppVersion() -> String {
let versionNumber = Bundle.main.object(forInfoDictionaryKey: "CFBundleShortVersionString") as! String
let buildNumber = Bundle.main.object(forInfoDictionaryKey: "CFBundleVersion") as! String
let version = "\(versionNumber)(\(buildNumber))"
print("\(ForceUpdateChecker.TAG) : version: \(version)")
return version
}
}