fix bugs of the passcode function
This commit is contained in:
parent
a31e9776fe
commit
f14c4662cb
6 changed files with 22 additions and 13 deletions
|
|
@ -24,13 +24,15 @@ class AppDelegate: UIResponder, UIApplicationDelegate {
|
||||||
func applicationWillResignActive(_ application: UIApplication) {
|
func applicationWillResignActive(_ application: UIApplication) {
|
||||||
// Sent when the application is about to move from active to inactive state. This can occur for certain types of temporary interruptions (such as an incoming phone call or SMS message) or when the user quits the application and it begins the transition to the background state.
|
// Sent when the application is about to move from active to inactive state. This can occur for certain types of temporary interruptions (such as an incoming phone call or SMS message) or when the user quits the application and it begins the transition to the background state.
|
||||||
// Use this method to pause ongoing tasks, disable timers, and invalidate graphics rendering callbacks. Games should use this method to pause the game.
|
// Use this method to pause ongoing tasks, disable timers, and invalidate graphics rendering callbacks. Games should use this method to pause the game.
|
||||||
let passcodeEnterViewController = PasscodeLockViewController(state: .enter, configuration: Globals.shared.passcodeConfiguration)
|
|
||||||
UIApplication.shared.keyWindow?.rootViewController?.present(passcodeEnterViewController, animated: true, completion: nil)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func applicationDidEnterBackground(_ application: UIApplication) {
|
func applicationDidEnterBackground(_ application: UIApplication) {
|
||||||
// Use this method to release shared resources, save user data, invalidate timers, and store enough application state information to restore your application to its current state in case it is terminated later.
|
// Use this method to release shared resources, save user data, invalidate timers, and store enough application state information to restore your application to its current state in case it is terminated later.
|
||||||
// If your application supports background execution, this method is called instead of applicationWillTerminate: when the user quits.
|
// If your application supports background execution, this method is called instead of applicationWillTerminate: when the user quits.
|
||||||
|
if PasscodeLockRepository().hasPasscode {
|
||||||
|
let passcodeEnterViewController = PasscodeLockViewController(state: .enter, configuration: Globals.shared.passcodeConfiguration)
|
||||||
|
UIApplication.shared.keyWindow?.rootViewController?.present(passcodeEnterViewController, animated: true, completion: nil)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func applicationWillEnterForeground(_ application: UIApplication) {
|
func applicationWillEnterForeground(_ application: UIApplication) {
|
||||||
|
|
|
||||||
|
|
@ -164,8 +164,8 @@
|
||||||
<nil key="textColor"/>
|
<nil key="textColor"/>
|
||||||
<nil key="highlightedColor"/>
|
<nil key="highlightedColor"/>
|
||||||
</label>
|
</label>
|
||||||
<label opaque="NO" multipleTouchEnabled="YES" contentMode="left" text="On" textAlignment="right" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" id="HXb-ZX-HUv">
|
<label opaque="NO" multipleTouchEnabled="YES" contentMode="left" text="Off" textAlignment="right" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" id="HXb-ZX-HUv">
|
||||||
<rect key="frame" x="356.66666666666669" y="11.999999999999998" width="22.333333333333332" height="20.333333333333332"/>
|
<rect key="frame" x="354.66666666666669" y="11.999999999999998" width="24.333333333333332" height="20.333333333333332"/>
|
||||||
<autoresizingMask key="autoresizingMask"/>
|
<autoresizingMask key="autoresizingMask"/>
|
||||||
<fontDescription key="fontDescription" type="system" pointSize="17"/>
|
<fontDescription key="fontDescription" type="system" pointSize="17"/>
|
||||||
<color key="textColor" white="0.66666666666666663" alpha="1" colorSpace="calibratedWhite"/>
|
<color key="textColor" white="0.66666666666666663" alpha="1" colorSpace="calibratedWhite"/>
|
||||||
|
|
|
||||||
|
|
@ -8,12 +8,13 @@
|
||||||
|
|
||||||
import Foundation
|
import Foundation
|
||||||
import PasscodeLock
|
import PasscodeLock
|
||||||
|
import SwiftyUserDefaults
|
||||||
|
|
||||||
struct PasscodeLockConfiguration: PasscodeLockConfigurationType {
|
struct PasscodeLockConfiguration: PasscodeLockConfigurationType {
|
||||||
|
|
||||||
let repository: PasscodeRepositoryType
|
let repository: PasscodeRepositoryType
|
||||||
let passcodeLength = 4
|
let passcodeLength = 4
|
||||||
var isTouchIDAllowed = false
|
var isTouchIDAllowed = Defaults[.isTouchIDOn]
|
||||||
let shouldRequestTouchIDImmediately = true
|
let shouldRequestTouchIDImmediately = true
|
||||||
let maximumInccorectPasscodeAttempts = 3
|
let maximumInccorectPasscodeAttempts = 3
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -28,7 +28,6 @@ public class PasscodeLockRepository: PasscodeRepositoryType {
|
||||||
|
|
||||||
public func save(passcode: String) {
|
public func save(passcode: String) {
|
||||||
Defaults[.passcodeKey] = passcode
|
Defaults[.passcodeKey] = passcode
|
||||||
print(passcode)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public func check(passcode: String) -> Bool {
|
public func check(passcode: String) -> Bool {
|
||||||
|
|
@ -37,6 +36,5 @@ public class PasscodeLockRepository: PasscodeRepositoryType {
|
||||||
|
|
||||||
public func delete() {
|
public func delete() {
|
||||||
Defaults[.passcodeKey] = nil
|
Defaults[.passcodeKey] = nil
|
||||||
print("delete")
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -10,6 +10,7 @@ import UIKit
|
||||||
import Result
|
import Result
|
||||||
import SVProgressHUD
|
import SVProgressHUD
|
||||||
import SwiftyUserDefaults
|
import SwiftyUserDefaults
|
||||||
|
import PasscodeLock
|
||||||
|
|
||||||
class PasswordsViewController: UIViewController, UITableViewDataSource, UITableViewDelegate {
|
class PasswordsViewController: UIViewController, UITableViewDataSource, UITableViewDelegate {
|
||||||
private var passwordEntities: [PasswordEntity]?
|
private var passwordEntities: [PasswordEntity]?
|
||||||
|
|
@ -53,6 +54,11 @@ class PasswordsViewController: UIViewController, UITableViewDataSource, UITableV
|
||||||
|
|
||||||
override func viewDidLoad() {
|
override func viewDidLoad() {
|
||||||
super.viewDidLoad()
|
super.viewDidLoad()
|
||||||
|
|
||||||
|
if PasscodeLockRepository().hasPasscode {
|
||||||
|
let passcodeEnterViewController = PasscodeLockViewController(state: .enter, configuration: Globals.shared.passcodeConfiguration)
|
||||||
|
UIApplication.shared.keyWindow?.rootViewController?.present(passcodeEnterViewController, animated: true, completion: nil)
|
||||||
|
}
|
||||||
passwordEntities = PasswordStore.shared.fetchPasswordEntityCoreData()
|
passwordEntities = PasswordStore.shared.fetchPasswordEntityCoreData()
|
||||||
NotificationCenter.default.addObserver(self, selector: #selector(PasswordsViewController.actOnPasswordUpdatedNotification), name: NSNotification.Name(rawValue: "passwordUpdated"), object: nil)
|
NotificationCenter.default.addObserver(self, selector: #selector(PasswordsViewController.actOnPasswordUpdatedNotification), name: NSNotification.Name(rawValue: "passwordUpdated"), object: nil)
|
||||||
NotificationCenter.default.addObserver(self, selector: #selector(PasswordsViewController.actOnPasswordStoreErasedNotification), name: NSNotification.Name(rawValue: "passwordStoreErased"), object: nil)
|
NotificationCenter.default.addObserver(self, selector: #selector(PasswordsViewController.actOnPasswordStoreErasedNotification), name: NSNotification.Name(rawValue: "passwordStoreErased"), object: nil)
|
||||||
|
|
@ -161,13 +167,11 @@ class PasswordsViewController: UIViewController, UITableViewDataSource, UITableV
|
||||||
func actOnPasswordUpdatedNotification() {
|
func actOnPasswordUpdatedNotification() {
|
||||||
passwordEntities = PasswordStore.shared.fetchPasswordEntityCoreData()
|
passwordEntities = PasswordStore.shared.fetchPasswordEntityCoreData()
|
||||||
reloadTableView(data: passwordEntities!)
|
reloadTableView(data: passwordEntities!)
|
||||||
print("actOnPasswordUpdatedNotification")
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func actOnPasswordStoreErasedNotification() {
|
func actOnPasswordStoreErasedNotification() {
|
||||||
passwordEntities = PasswordStore.shared.fetchPasswordEntityCoreData()
|
passwordEntities = PasswordStore.shared.fetchPasswordEntityCoreData()
|
||||||
reloadTableView(data: passwordEntities!)
|
reloadTableView(data: passwordEntities!)
|
||||||
print("actOnPasswordErasedNotification")
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -14,7 +14,8 @@ import PasscodeLock
|
||||||
|
|
||||||
class SettingsTableViewController: UITableViewController {
|
class SettingsTableViewController: UITableViewController {
|
||||||
|
|
||||||
let repository = PasscodeLockRepository()
|
let touchIDSwitch = UISwitch(frame: CGRect.zero)
|
||||||
|
|
||||||
@IBOutlet weak var pgpKeyTableViewCell: UITableViewCell!
|
@IBOutlet weak var pgpKeyTableViewCell: UITableViewCell!
|
||||||
@IBOutlet weak var touchIDTableViewCell: UITableViewCell!
|
@IBOutlet weak var touchIDTableViewCell: UITableViewCell!
|
||||||
@IBOutlet weak var passcodeTableViewCell: UITableViewCell!
|
@IBOutlet weak var passcodeTableViewCell: UITableViewCell!
|
||||||
|
|
@ -108,7 +109,6 @@ class SettingsTableViewController: UITableViewController {
|
||||||
|
|
||||||
override func viewDidLoad() {
|
override func viewDidLoad() {
|
||||||
super.viewDidLoad()
|
super.viewDidLoad()
|
||||||
let touchIDSwitch = UISwitch(frame: CGRect.zero)
|
|
||||||
touchIDTableViewCell.accessoryView = touchIDSwitch
|
touchIDTableViewCell.accessoryView = touchIDSwitch
|
||||||
touchIDSwitch.addTarget(self, action: #selector(touchIDSwitchAction), for: UIControlEvents.valueChanged)
|
touchIDSwitch.addTarget(self, action: #selector(touchIDSwitchAction), for: UIControlEvents.valueChanged)
|
||||||
if Defaults[.isTouchIDOn] {
|
if Defaults[.isTouchIDOn] {
|
||||||
|
|
@ -116,11 +116,11 @@ class SettingsTableViewController: UITableViewController {
|
||||||
} else {
|
} else {
|
||||||
touchIDSwitch.isOn = false
|
touchIDSwitch.isOn = false
|
||||||
}
|
}
|
||||||
if repository.hasPasscode {
|
if PasscodeLockRepository().hasPasscode {
|
||||||
self.passcodeTableViewCell.detailTextLabel?.text = "On"
|
self.passcodeTableViewCell.detailTextLabel?.text = "On"
|
||||||
print(Defaults[.passcodeKey]!)
|
|
||||||
} else {
|
} else {
|
||||||
self.passcodeTableViewCell.detailTextLabel?.text = "Off"
|
self.passcodeTableViewCell.detailTextLabel?.text = "Off"
|
||||||
|
touchIDSwitch.isEnabled = false
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -146,8 +146,10 @@ class SettingsTableViewController: UITableViewController {
|
||||||
|
|
||||||
func touchIDSwitchAction(uiSwitch: UISwitch) {
|
func touchIDSwitchAction(uiSwitch: UISwitch) {
|
||||||
if uiSwitch.isOn {
|
if uiSwitch.isOn {
|
||||||
|
Defaults[.isTouchIDOn] = true
|
||||||
Globals.shared.passcodeConfiguration.isTouchIDAllowed = true
|
Globals.shared.passcodeConfiguration.isTouchIDAllowed = true
|
||||||
} else {
|
} else {
|
||||||
|
Defaults[.isTouchIDOn] = false
|
||||||
Globals.shared.passcodeConfiguration.isTouchIDAllowed = false
|
Globals.shared.passcodeConfiguration.isTouchIDAllowed = false
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -160,6 +162,7 @@ class SettingsTableViewController: UITableViewController {
|
||||||
let removePasscodeAction = UIAlertAction(title: "Remove Passcode", style: .destructive) { [unowned self] _ in
|
let removePasscodeAction = UIAlertAction(title: "Remove Passcode", style: .destructive) { [unowned self] _ in
|
||||||
passcodeRemoveViewController.successCallback = { _ in
|
passcodeRemoveViewController.successCallback = { _ in
|
||||||
self.passcodeTableViewCell.detailTextLabel?.text = "Off"
|
self.passcodeTableViewCell.detailTextLabel?.text = "Off"
|
||||||
|
self.touchIDSwitch.isEnabled = false
|
||||||
}
|
}
|
||||||
self.present(passcodeRemoveViewController, animated: true, completion: nil)
|
self.present(passcodeRemoveViewController, animated: true, completion: nil)
|
||||||
}
|
}
|
||||||
|
|
@ -179,6 +182,7 @@ class SettingsTableViewController: UITableViewController {
|
||||||
let passcodeSetViewController = PasscodeLockViewController(state: .set, configuration: Globals.shared.passcodeConfiguration)
|
let passcodeSetViewController = PasscodeLockViewController(state: .set, configuration: Globals.shared.passcodeConfiguration)
|
||||||
passcodeSetViewController.successCallback = { _ in
|
passcodeSetViewController.successCallback = { _ in
|
||||||
self.passcodeTableViewCell.detailTextLabel?.text = "On"
|
self.passcodeTableViewCell.detailTextLabel?.text = "On"
|
||||||
|
self.touchIDSwitch.isEnabled = true
|
||||||
}
|
}
|
||||||
present(passcodeSetViewController, animated: true, completion: nil)
|
present(passcodeSetViewController, animated: true, completion: nil)
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue