COVIDSafe code from version 1.2

This commit is contained in:
covidsafe-support 2020-05-15 00:47:40 -07:00
parent 3640e52eb2
commit cae9823e44
97 changed files with 1001 additions and 465 deletions

View file

@ -11,22 +11,56 @@ import KeychainSwift
class InitialScreenViewController: UIViewController {
let displayTimeSeconds: Int = 4
let giveupTimeSeconds = 8.0
var isKeychainAvailable = false
var isDisplayTimeElapsed = false
let keychain = KeychainSwift()
var giveupTimer: Timer?
override func viewDidLoad() {
super.viewDidLoad()
switch UIApplication.shared.isProtectedDataAvailable {
case true :
isKeychainAvailable = true
break
case false:
NotificationCenter.default.addObserver(self, selector: #selector(setKeychainAvailable(_:)), name: UIApplication.protectedDataDidBecomeAvailableNotification, object: nil)
break
}
}
override func viewDidAppear(_ animated: Bool) {
super.viewDidAppear(animated)
view.window?.tintColor = .covidSafeColor
let showAppDelay = DispatchTime.now() + .seconds(displayTimeSeconds)
DispatchQueue.main.asyncAfter(deadline: showAppDelay, execute: {
self.performCheck()
self.isDisplayTimeElapsed = true
if(self.proceedWithChecks()) {
self.performCheck()
}
})
// add give up action in case the keychain notification in not received after 8 seconds
giveupTimer = Timer.scheduledTimer(withTimeInterval: giveupTimeSeconds, repeats: false) { timer in
self.performSegue(withIdentifier: "initialPersonalDetailsSegue", sender: self)
}
}
@objc
func setKeychainAvailable(_ notification: Notification) {
NotificationCenter.default.removeObserver(self, name: UIApplication.protectedDataDidBecomeAvailableNotification, object: nil)
isKeychainAvailable = true
if(self.proceedWithChecks()) {
self.performCheck()
}
}
private func proceedWithChecks() -> Bool {
return isDisplayTimeElapsed && isKeychainAvailable
}
private func performCheck() {
let keychain = KeychainSwift()
giveupTimer?.invalidate()
let isLoggedIn: Bool = (keychain.get("JWT_TOKEN") != nil)
if !UserDefaults.standard.bool(forKey: "completedIWantToHelp") {
// old app signed out here