fix bugs of the passcode function

This commit is contained in:
Bob Sun 2017-02-07 20:57:06 +08:00
parent a31e9776fe
commit f14c4662cb
No known key found for this signature in database
GPG key ID: 1F86BA2052FED3B4
6 changed files with 22 additions and 13 deletions

View file

@ -24,13 +24,15 @@ class AppDelegate: UIResponder, UIApplicationDelegate {
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.
// 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) {
// 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 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) {

View file

@ -164,8 +164,8 @@
<nil key="textColor"/>
<nil key="highlightedColor"/>
</label>
<label opaque="NO" multipleTouchEnabled="YES" contentMode="left" text="On" 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"/>
<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="354.66666666666669" y="11.999999999999998" width="24.333333333333332" height="20.333333333333332"/>
<autoresizingMask key="autoresizingMask"/>
<fontDescription key="fontDescription" type="system" pointSize="17"/>
<color key="textColor" white="0.66666666666666663" alpha="1" colorSpace="calibratedWhite"/>

View file

@ -8,12 +8,13 @@
import Foundation
import PasscodeLock
import SwiftyUserDefaults
struct PasscodeLockConfiguration: PasscodeLockConfigurationType {
let repository: PasscodeRepositoryType
let passcodeLength = 4
var isTouchIDAllowed = false
var isTouchIDAllowed = Defaults[.isTouchIDOn]
let shouldRequestTouchIDImmediately = true
let maximumInccorectPasscodeAttempts = 3

View file

@ -28,7 +28,6 @@ public class PasscodeLockRepository: PasscodeRepositoryType {
public func save(passcode: String) {
Defaults[.passcodeKey] = passcode
print(passcode)
}
public func check(passcode: String) -> Bool {
@ -37,6 +36,5 @@ public class PasscodeLockRepository: PasscodeRepositoryType {
public func delete() {
Defaults[.passcodeKey] = nil
print("delete")
}
}

View file

@ -10,6 +10,7 @@ import UIKit
import Result
import SVProgressHUD
import SwiftyUserDefaults
import PasscodeLock
class PasswordsViewController: UIViewController, UITableViewDataSource, UITableViewDelegate {
private var passwordEntities: [PasswordEntity]?
@ -53,6 +54,11 @@ class PasswordsViewController: UIViewController, UITableViewDataSource, UITableV
override func 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()
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)
@ -161,13 +167,11 @@ class PasswordsViewController: UIViewController, UITableViewDataSource, UITableV
func actOnPasswordUpdatedNotification() {
passwordEntities = PasswordStore.shared.fetchPasswordEntityCoreData()
reloadTableView(data: passwordEntities!)
print("actOnPasswordUpdatedNotification")
}
func actOnPasswordStoreErasedNotification() {
passwordEntities = PasswordStore.shared.fetchPasswordEntityCoreData()
reloadTableView(data: passwordEntities!)
print("actOnPasswordErasedNotification")
}

View file

@ -14,7 +14,8 @@ import PasscodeLock
class SettingsTableViewController: UITableViewController {
let repository = PasscodeLockRepository()
let touchIDSwitch = UISwitch(frame: CGRect.zero)
@IBOutlet weak var pgpKeyTableViewCell: UITableViewCell!
@IBOutlet weak var touchIDTableViewCell: UITableViewCell!
@IBOutlet weak var passcodeTableViewCell: UITableViewCell!
@ -108,7 +109,6 @@ class SettingsTableViewController: UITableViewController {
override func viewDidLoad() {
super.viewDidLoad()
let touchIDSwitch = UISwitch(frame: CGRect.zero)
touchIDTableViewCell.accessoryView = touchIDSwitch
touchIDSwitch.addTarget(self, action: #selector(touchIDSwitchAction), for: UIControlEvents.valueChanged)
if Defaults[.isTouchIDOn] {
@ -116,11 +116,11 @@ class SettingsTableViewController: UITableViewController {
} else {
touchIDSwitch.isOn = false
}
if repository.hasPasscode {
if PasscodeLockRepository().hasPasscode {
self.passcodeTableViewCell.detailTextLabel?.text = "On"
print(Defaults[.passcodeKey]!)
} else {
self.passcodeTableViewCell.detailTextLabel?.text = "Off"
touchIDSwitch.isEnabled = false
}
}
@ -146,8 +146,10 @@ class SettingsTableViewController: UITableViewController {
func touchIDSwitchAction(uiSwitch: UISwitch) {
if uiSwitch.isOn {
Defaults[.isTouchIDOn] = true
Globals.shared.passcodeConfiguration.isTouchIDAllowed = true
} else {
Defaults[.isTouchIDOn] = false
Globals.shared.passcodeConfiguration.isTouchIDAllowed = false
}
}
@ -160,6 +162,7 @@ class SettingsTableViewController: UITableViewController {
let removePasscodeAction = UIAlertAction(title: "Remove Passcode", style: .destructive) { [unowned self] _ in
passcodeRemoveViewController.successCallback = { _ in
self.passcodeTableViewCell.detailTextLabel?.text = "Off"
self.touchIDSwitch.isEnabled = false
}
self.present(passcodeRemoveViewController, animated: true, completion: nil)
}
@ -179,6 +182,7 @@ class SettingsTableViewController: UITableViewController {
let passcodeSetViewController = PasscodeLockViewController(state: .set, configuration: Globals.shared.passcodeConfiguration)
passcodeSetViewController.successCallback = { _ in
self.passcodeTableViewCell.detailTextLabel?.text = "On"
self.touchIDSwitch.isEnabled = true
}
present(passcodeSetViewController, animated: true, completion: nil)
}