Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 18 additions & 4 deletions PasscodeLock/PasscodeLock/EnterPasscodeState.swift
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,17 @@ struct EnterPasscodeState: PasscodeLockStateType {
let isCancellableAction: Bool
var isTouchIDAllowed = true

private var inccorectPasscodeAttempts = 0
static let incorrectPasscodeAttemptsKey = "incorrectPasscodeAttempts"
static var incorrectPasscodeAttempts: Int {
get {
return NSUserDefaults.standardUserDefaults().integerForKey(incorrectPasscodeAttemptsKey)
}
set {
NSUserDefaults.standardUserDefaults().setInteger(newValue, forKey: incorrectPasscodeAttemptsKey)
}
}


private var isNotificationSent = false

init(allowCancellation: Bool = false) {
Expand All @@ -33,21 +43,25 @@ struct EnterPasscodeState: PasscodeLockStateType {
return
}

var incorrectPasscodeAttempts = EnterPasscodeState.incorrectPasscodeAttempts
if passcode == currentPasscode {

lock.delegate?.passcodeLockDidSucceed(lock)

incorrectPasscodeAttempts = 0
} else {

inccorectPasscodeAttempts += 1
incorrectPasscodeAttempts += 1

if inccorectPasscodeAttempts >= lock.configuration.maximumInccorectPasscodeAttempts {
if incorrectPasscodeAttempts >= lock.configuration.maximumInccorectPasscodeAttempts {

postNotification()
incorrectPasscodeAttempts = 0
}

lock.delegate?.passcodeLockDidFail(lock)
}

EnterPasscodeState.incorrectPasscodeAttempts = incorrectPasscodeAttempts
}

private mutating func postNotification() {
Expand Down
2 changes: 1 addition & 1 deletion PasscodeLock/PasscodeLock/PasscodeLock.swift
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ public class PasscodeLock: PasscodeLockType {
dispatch_async(dispatch_get_main_queue()) {

if success {

EnterPasscodeState.incorrectPasscodeAttempts = 0
self.delegate?.passcodeLockDidSucceed(self)
}
}
Expand Down